How is the calculation of types in Haskell -


lets say

  flip :: (a->b->c) ->b->a->c   const ::d->e->d 

type of (flip const) be

  a=d,b=e,c=d 

in

  b->a->c 

so type be

  e->d->d 

but (map take) its

  [int]->[[a]]->[[a]] 

so didn't understand how ghci 1 calculated. understood [[a]]->[[a]] why , how [int] ?

edit: example if we'd write in ghci

  :t flip const    return b->c->c 

and ghci calculate did.

but

 map :: (a->b)->[a]->[b]  take :: int->[c]->[c] 

so why map take

  [int]->[[a]->[a]] 

why [int] how did ghci calculate that

you should copy , paste types see, not re-type them question. reason saw wrong. type map take is:

map take :: [int] -> [[a] -> [a]] 

in other words, unification works such:

:t map map :: (a -> b) -> [a] -> [b] :t take take :: int -> [c] -> [c] 

so when applying take first argument map a ~ int , b ~ [c] -> [c] (notice function). performing these replacements in map type , applying first argument:

map take :: [a] -> [b]        (for specific 'a' , 'b') -- recall ~ int map take :: [int] -> [b]      (for specific 'b') -- recall b ~ [c] -> [c] map take :: [int] -> [[c] -> [c]] 

yay, map take expect. function operates on lists of ints , results in list of functions take number of elements start of list.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -