Re: [Haskell-cafe] Sequence differences
Clearly, I have some reading to do. Thanks, Michael --- On Fri, 4/10/09, Ketil Malde <ketil@malde.org> wrote: From: Ketil Malde <ketil@malde.org> Subject: Re: [Haskell-cafe] Sequence differences To: "michael rice" <nowgate@yahoo.com> Cc: "haskell Cafe mailing list" <haskell-cafe@haskell.org>, "Joe Fredette" <jfredett@gmail.com> Date: Friday, April 10, 2009, 3:52 PM michael rice <nowgate@yahoo.com> writes:
map :: (a -> b) -> [a] -> [b] <== I'm assuming this is correct
This is the type of 'map', yes. Btw, ou can check types in GHCi with the :i command.
s f ls
seems much like
map f ls
but instead looks like
s :: (a -> a -> a) -> [a] -> [a]
If you look at the definition:
s f [] = [] s f [x] = [x] s f l = [ a f b | (a,b) <- zip (init l) (tail l)]
You'll notice that the second clause, namely s f [x] = [x] produces the second parameter [x] (of type [a]) as its output, and thus the types must be the same as well. Also (assuming it is 'f a b' and not 'a f b' in the list comprehension), f is applied to two parameters, so it'll have to be of type (x -> y -> z), and since the two input parameters come from the originating list, x and y must be the same as a, and since we have seen the result list also has the same type, z must be the same as a, too. Thus f must have type (a -> a -> a). Unclear? Clear? Operating thetan? -k -- If I haven't seen further, it is by standing in the footprints of giants
participants (1)
-
michael rice