[Haskell-cafe] nested function application question

Ross Mellgren rmm-haskell at z.odi.ac
Mon Jan 5 13:29:10 EST 2009


In this case you have to use parens -- two dollar signs, like this

B.intercalate $ B.intercalate ByteString [ByteString] $ [ByteString]

would also not type check -- it is exactly equivalent to your first  
example:

B.intercalate (B.intercalate ByteString [ByteString] ([ByteString]))

just with one level of extra parentheses.

If for some reason you absolutely need to avoid parentheses (mostly as  
a thought exercise, I guess), you'd have to have a flipped version of  
intercalate:

flippedIntercalate :: [ByteString] -> ByteString -> ByteString
flippedIntercalate = flip B.intercalate

flippedIntercalate [ByteString] $ B.intercalate ByteString [ByteString]

of course, this is pretty contrived.

-Ross


On Jan 5, 2009, at 1:23 PM, Galchin, Vasili wrote:

> yep ... that is exactly what I meant!! so can I use more $'s or must  
> I use parens (as you did) to disambiguate?
>
> Vasili
>
> On Mon, Jan 5, 2009 at 12:18 PM, Ross Mellgren <rmm- 
> haskell at z.odi.ac> wrote:
> Did you mean:
>
> B.intercalate (B.intercalate ByteString [ByteString]) [ByteString]
>
> ($) applies all the way to the right, so you were giving the inner  
> intercalate two lists of ByteString.
>
> -Ross
>
>
> On Jan 5, 2009, at 1:17 PM, Galchin, Vasili wrote:
>
>> Hi Max,
>>
>>        That is what should happen .... The inner B.intercalate will  
>> produce the ByteString to be used by the B.intercalate.  ??
>>
>> Vasili
>>
>> On Mon, Jan 5, 2009 at 12:13 PM, Max Rabkin <max.rabkin at gmail.com>  
>> wrote:
>> 2009/1/5 Galchin, Vasili <vigalchin at gmail.com>:
>> > Hello,
>> >
>> >       I have the following:
>> >
>> >             B.intercalate $ B.intercalate
>> >                   ByteString
>> >                   [ByteString]
>> >                   [ByteString]
>> >
>> >       I get a type error with this. If I  comment out the 2nd  
>> B.intercalate
>> > and the third parameter I get no type errors.
>>
>> B.intercalate needs a ByteString and a list of ByteStrings. Two
>> B.intercalates need two ByteStrings and two lists of ByteStrings.
>>
>> --Max
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090105/585d8af9/attachment-0001.htm


More information about the Haskell-Cafe mailing list