[Haskell] Type of y f = f . f

Till Mossakowski till at informatik.uni-bremen.de
Mon Feb 28 05:10:58 EST 2005


The name y suggests that you want to define the fixpoint combinator.
This works as follows:

Prelude> let y f = f (y f)
Prelude> :type y
y :: forall t. (t -> t) -> t
Prelude> y (\fac n -> if n == 0 then 1 else n*fac(n-1)) 10
3628800
Prelude>


Till

Pedro Vasconcelos wrote:
> On Mon, 28 Feb 2005 03:50:14 -0500
> Jim Apple <japple at freeshell.org> wrote:
> 
> 
>>Is there a type we can give to
>>
>>y f = f . f
>>
>>y id
>>y head
>>y fst
>>
>>are all typeable?
>>
> 
> 
> Using ghci:
> 
> Prelude> let y f = f.f
> Prelude> :t y
> y :: forall c. (c -> c) -> c -> c
> 
> So it admits principal type (a->a) -> a->a. From this you can see that
> (y head) and (y fst) cannot be typed, whereas (y id) can. BTW, this
> function is usually named 'twice'.
> 
> Best regards,
> 
> Pedro
> 


-- 
Till Mossakowski               Phone +49-421-218-4683
Dept. of Computer Science      Fax +49-421-218-3054
University of Bremen           till at tzi.de
P.O.Box 330440, D-28334 Bremen http://www.tzi.de/~till


More information about the Haskell mailing list