
Notice that, (\x -> x) a reduces to a, so (\a b c -> a b c) x (y-z) z reduces to x (y-z) z. You can therefore simplify your function quite a bit. wierdFunc x y z = if y-z > z then x (y-z) z else (\d e -> d) (y-z) z and you can still apply that lambda abstraction (beta-reduce) wierdFunc x y z = if y-z > z then x (y-z) z else y-z None of these (except, of course, fix and remainder) are recursive. A recursive function is just one that calls itself. For wierdFunc to be recursive, the identifier wierdFunc would have to occur in the right-hand side of it's definition.
Thanks for your help. For some reason I didn't think "x (y - z) z" and "y - z" had the same type. I am still trying to understand how they do. Also, had a feeling the fix function was related to the "Y" combinator; it seems they're the same thing! http://en.wikipedia.org/wiki/Y_combinator thanks again, -andrew

Also, had a feeling the fix function was related to the "Y" combinator; it seems they're the same thing!
Yes, they're the same in effect, although historically fix is often defined recursively or taken as a primitive, whereas Y has its roots in the lambda calculus, where it is defined as: Y = \f.(\x.f(x x))(\x.f(x x)) which, you will note, is not recursive, yet has the property that Y f = f (Y f), so that it is in fact a fixpoint generator. (You might want to try proving this -- it's easy and illuminating.) Unfortunately, this expression will not type-check in Haskell or ML because of limitations of the Hindley-Milner type system :-(. There are ways around this, but they involve introducing a data structure to avoid problems with infinite types. -Paul
participants (2)
-
Harris, Andrew
-
Paul Hudak