Y Combinator in Haskell

前端 未结 5 1463
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 12:44

Is it possible to write the Y Combinator in Haskell?

It seems like it would have an infinitely recursive type.

 Y :: f -> b -> c
 where f :: (f -         


        
5条回答
  •  死守一世寂寞
    2020-12-07 13:25

    Here's a non-recursive definition of the y-combinator in haskell:

    newtype Mu a = Mu (Mu a -> a)
    y f = (\h -> h $ Mu h) (\x -> f . (\(Mu g) -> g) x $ x)
    

    hat tip

提交回复
热议问题