First time using Haskell

In Haskell it is more common to use the peano construction:

data Nat = Zero | Succ Nat

Of course just using the Integer (or Natural) type is much faster.

Why would you need von Neumann ordinals specifically?

Edit: I think you can do Neumann ordinals like this I guess:

import qualified Data.Set as Set

newtype NestedSet = NestedSet { getNestedSet :: Set.Set NestedSet }
  deriving (Eq, Ord, Show)

hh :: [NestedSet]
hh = iterate (\x -> NestedSet (Set.insert x (getNestedSet x))) (NestedSet Set.empty)

And again in GHCi:

ghci> mapM_ print $ take 4 hh
NestedSet {getNestedSet = fromList []}
NestedSet {getNestedSet = fromList [NestedSet {getNestedSet = fromList []}]}
NestedSet {getNestedSet = fromList [NestedSet {getNestedSet = fromList []},NestedSet {getNestedSet = fromList [NestedSet {getNestedSet = fromList []}]}]}
NestedSet {getNestedSet = fromList [NestedSet {getNestedSet = fromList []},NestedSet {getNestedSet = fromList [NestedSet {getNestedSet = fromList []}]},NestedSet {getNestedSet = fromList [NestedSet {getNestedSet = fromList []},NestedSet {getNestedSet = fromList [NestedSet {getNestedSet = fromList []}]}]}]}
2 Likes