Help with possible Haskell type inference quiz questions
Posted
by Linda Cohen
on Stack Overflow
See other posts from Stack Overflow
or by Linda Cohen
Published on 2010-05-11T21:03:23Z
Indexed on
2010/05/11
21:04 UTC
Read the original article
Hit count: 311
foldr:: (a -> b -> b) -> b -> [a] -> b
map :: (a -> b) -> [a] -> [b]
mys :: a -> a
(.) :: (a -> b) -> (c -> a) -> c -> b
what is inferred type of:
a.map mys ::
b.mys map ::
c.foldr map ::
d.foldr map.mys ::
I've tried to create mys myself using mys n = n + 2 but the type of that is
mys :: Num a => a -> a
What's the difference between Num a => a -> a and just a -> a? Or what does 'Num a =>' mean? Is it that mys would only take Num type?
So anyways,
a) I got [a] -> [a] I think because it would just take a list and return it +2'd according to my definition of mys
b) (a -> b) -> [a] -> [b] I think because map still needs take both arguments like (*3) and a list then returns [a] which goes to mys and returns [b]
c) I'm not sure how to do this 1.
d) I'm not sure how to do this 1 either but map.mys means do mys first then map right?
Are my answers and thoughts correct? If not, why not?
THANKS!
© Stack Overflow or respective owner