Y Combinator in Haskell

前端 未结 5 1456
爱一瞬间的悲伤
爱一瞬间的悲伤 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:24

    Oh

    this wiki page and This Stack Overflow answer seem to answer my question.
    I will write up more of an explanation later.

    Now, I've found something interesting about that Mu type. Consider S = Mu Bool.

    data S = S (S -> Bool)
    

    If one treats S as a set and that equals sign as isomorphism, then the equation becomes

    S ⇋ S -> Bool ⇋ Powerset(S)
    

    So S is the set of sets that are isomorphic to their powerset! But we know from Cantor's diagonal argument that the cardinality of Powerset(S) is always strictly greater than the cardinality of S, so they are never isomorphic. I think this is why you can now define a fixed point operator, even though you can't without one.

提交回复
热议问题