nested function application question
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. Regards, Vasili
2009/1/5 Galchin, Vasili <vigalchin@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
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@gmail.com> wrote:
2009/1/5 Galchin, Vasili <vigalchin@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
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@gmail.com> wrote: 2009/1/5 Galchin, Vasili <vigalchin@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
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@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@gmail.com> wrote:
2009/1/5 Galchin, Vasili <vigalchin@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
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@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@gmail.com> wrote: 2009/1/5 Galchin, Vasili <vigalchin@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
2009/1/5 Ross Mellgren <rmm-haskell@z.odi.ac>:
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:
Or a version of ($) that associates differently. infixl 0 $$ f $$ x = f x *Main Data.ByteString> :t \x y z -> intercalate $$ intercalate x y $$ z \x y z -> intercalate $$ intercalate x y $$ z :: ByteString -> [ByteString] -> [ByteString] -> ByteString -- Dave Menendez <dave@zednenem.com> <http://www.eyrie.org/~zednenem/>
Thank you everybody! Vasili On Mon, Jan 5, 2009 at 12:57 PM, David Menendez <dave@zednenem.com> wrote:
2009/1/5 Ross Mellgren <rmm-haskell@z.odi.ac>:
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:
Or a version of ($) that associates differently.
infixl 0 $$
f $$ x = f x
*Main Data.ByteString> :t \x y z -> intercalate $$ intercalate x y $$ z \x y z -> intercalate $$ intercalate x y $$ z :: ByteString -> [ByteString] -> [ByteString] -> ByteString
-- Dave Menendez <dave@zednenem.com> <http://www.eyrie.org/~zednenem/ <http://www.eyrie.org/%7Ezednenem/>>
On 2009 Jan 5, at 13:57, David Menendez wrote:
2009/1/5 Ross Mellgren <rmm-haskell@z.odi.ac>:
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:
Or a version of ($) that associates differently.
infixl 0 $$
f $$ x = f x
*Main Data.ByteString> :t \x y z -> intercalate $$ intercalate x y $ $ z \x y z -> intercalate $$ intercalate x y $$ z :: ByteString -> [ByteString] -> [ByteString] -> ByteString
...at which point we're reinventing Applicative, no? -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
On Mon, Jan 5, 2009 at 3:16 PM, Brandon S. Allbery KF8NH <allbery@ece.cmu.edu> wrote:
On 2009 Jan 5, at 13:57, David Menendez wrote:
2009/1/5 Ross Mellgren <rmm-haskell@z.odi.ac>:
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:
Or a version of ($) that associates differently.
infixl 0 $$
f $$ x = f x
*Main Data.ByteString> :t \x y z -> intercalate $$ intercalate x y $$ z \x y z -> intercalate $$ intercalate x y $$ z :: ByteString -> [ByteString] -> [ByteString] -> ByteString
...at which point we're reinventing Applicative, no?
Is "const" a reinvention of "return"? You could write the above code with (<*>), but you'd need to convert back and forth from Identity in order to get the proper Applicative instance. runIdentity $ Identity B.intercalate <*> Identity (B.intercalate x y) <*> Identity z At that point, you might as well save the noise and write, B.intercalate (B.intercalate x y) z -- Dave Menendez <dave@zednenem.com> <http://www.eyrie.org/~zednenem/>
On Mon, Jan 5, 2009 at 10:17 AM, Galchin, Vasili <vigalchin@gmail.com> wrote:
Hi Max,
That is what should happen .... The inner B.intercalate will produce the ByteString to be used by the B.intercalate. ??
Vasili
Of course. My mistake. Ross Mellgren seems to be on the money though. --Max
participants (5)
-
Brandon S. Allbery KF8NH -
David Menendez -
Galchin, Vasili -
Max Rabkin -
Ross Mellgren