Way calculation of a function in Haskell using composition -
Way calculation of a function in Haskell using composition -
i have function in haskell:
thrit::(a->a)->a->a thrit f= f.f.f and want know how computer calculate expressions answer:
((thrit.thrit)(+1))0 9
((thrit thrit)(+1))0 27
let's expand expressions
((thrit . thrit) (+1)) 0 = (thrit (thrit (+1)) 0 = (thrit ((+1) . (+1) . (+1))) 0 = ((+1) . (+1) . (+1) . (+1) . (+1) . (+1) . (+1) . (+1) . (+1)) 0
which 9
((thrit thrit) (+1)) 0 = ((thrit . thrit . thrit) (+1)) 0 = (thrit (thrit (thrit (+1))) 0
you may have noticed (thrit (thrit (thrit (+1))) 0 3 times (thrit (thrit (+1)) 0
hence 27
haskell
Comments
Post a Comment