Cheng Zhang on Nostr: I was talking to my students about inductive and coinductive data types, and she ...
I was talking to my students about inductive and coinductive data types, and she asked what about `inf = Succ inf` in Haskell, now I cannot sleep.
The naive answer is that "this is actually a corecursion, thus defines infinity". However, the uncomfortable truth is that **Haskell semantics don't know whether definition is recursive or corecursive**.
Sometimes Haskell solves the fixpoint equation `inf = Succ inf` to infinity, instead of the least solution, which should be infinite loops.
Yet in other cases, Haskell will solve the fixpoint equation into its least solution: consider the following definition, which generates a infinite fixpoint equation where the variables are `eq n m` for all `n m in Nat`
```hs
eq Zero Zero = True
eq (Succ n) (Succ m) = eq n m
eq _ _ = False
```
the variable `eq inf inf`, in this case, is solved to its least solution infinite loop, instead of `True` like a proper corecursive language.
Intuitively, Haskell tries to explore the coalgebra generated by the fixpoint equations to compute its solutions.
**It seems like that Haskell solves to the final coalgebra when the reachable state is finite (i.e. regular), but solves to infinite loop when the reachable state is infinite.**
As a corollary, neither the standard DCPO semantics nor the standard final coalgebra semantics seems to fully capture the semantics of Haskell.
Published at
2026-05-16 08:28:26 UTCEvent JSON
{
"id": "afb903347d3f7cdbd39a3f7eec523f89acd8f096276f6bfce7c540feb1aafdcf",
"pubkey": "e613f8d3f4092d399e5125d1704bf2dffe686f6b92116e1921e78ea9cc6993dc",
"created_at": 1778920106,
"kind": 1,
"tags": [
[
"proxy",
"https://mathstodon.xyz/@czhang03/116583308125006603",
"web"
],
[
"proxy",
"https://mathstodon.xyz/users/czhang03/statuses/116583308125006603",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://mathstodon.xyz/users/czhang03/statuses/116583308125006603",
"pink.momostr"
],
[
"-"
]
],
"content": "I was talking to my students about inductive and coinductive data types, and she asked what about `inf = Succ inf` in Haskell, now I cannot sleep.\n\nThe naive answer is that \"this is actually a corecursion, thus defines infinity\". However, the uncomfortable truth is that **Haskell semantics don't know whether definition is recursive or corecursive**.\n\nSometimes Haskell solves the fixpoint equation `inf = Succ inf` to infinity, instead of the least solution, which should be infinite loops.\nYet in other cases, Haskell will solve the fixpoint equation into its least solution: consider the following definition, which generates a infinite fixpoint equation where the variables are `eq n m` for all `n m in Nat`\n```hs\neq Zero Zero = True\neq (Succ n) (Succ m) = eq n m\neq _ _ = False\n```\nthe variable `eq inf inf`, in this case, is solved to its least solution infinite loop, instead of `True` like a proper corecursive language.\n\nIntuitively, Haskell tries to explore the coalgebra generated by the fixpoint equations to compute its solutions. \n**It seems like that Haskell solves to the final coalgebra when the reachable state is finite (i.e. regular), but solves to infinite loop when the reachable state is infinite.**\nAs a corollary, neither the standard DCPO semantics nor the standard final coalgebra semantics seems to fully capture the semantics of Haskell.",
"sig": "4ec4ddeecc5367395422f52ffa64143839bb83f1f2d97e8a43048f7b02e37e56411049aaaf9c5696b179a5ba0029b31e4a48fb988e7abc58ec48929beb26a01b"
}