Why? Shouldn't this work for any type a? Michael ========== f :: [a] -> [a] f l = do x <- l return x ========== *Main> :r [1 of 1] Compiling Main ( test.hs, interpreted ) Ok, modules loaded: Main. *Main> f "abcde" "abcde" *Main> f [1,2,3,4,5] [1,2,3,4,5] *Main> "abcde" >>= f <interactive>:1:12: Couldn't match expected type `Char' against inferred type `m b' In the second argument of `(>>=)', namely `f' In the expression: "abcde" >>= f In the definition of `it': it = "abcde" >>= f *Main>
Because applying f to the list is not the same thing is applying bind to the list and f. Bob On 26 Feb 2011, at 20:17, michael rice wrote:
Why? Shouldn't this work for any type a?
Michael
==========
f :: [a] -> [a] f l = do x <- l return x
==========
*Main> :r [1 of 1] Compiling Main ( test.hs, interpreted ) Ok, modules loaded: Main. *Main> f "abcde" "abcde" *Main> f [1,2,3,4,5] [1,2,3,4,5] *Main> "abcde" >>= f
<interactive>:1:12: Couldn't match expected type `Char' against inferred type `m b' In the second argument of `(>>=)', namely `f' In the expression: "abcde" >>= f In the definition of `it': it = "abcde" >>= f *Main>
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Yeah, my bad. Thanks. Michael --- On Sat, 2/26/11, Stephen Tetley <stephen.tetley@gmail.com> wrote: From: Stephen Tetley <stephen.tetley@gmail.com> Subject: Re: [Haskell-cafe] Type problem To: Cc: haskell-cafe@haskell.org Date: Saturday, February 26, 2011, 3:24 PM Does this help? listbind :: [a] -> (a -> [b]) -> [b] listbind = (>>=) _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
michael rice -
Stephen Tetley -
Thomas Davie