
24 Aug
2008
24 Aug
'08
4:25 a.m.
Can you examples of both naive definitions and fast definitions of Nat? I'm curious.
Naive:
data Natural' = Zero | Succ Natural'
Fast:
type Nat = Word64
(or Word if you want to retrofit to Haskell-1.5, a.k.a. Haskell98 ;-).
newtype Natural = N Integer -- to be exported abstractly
instance Num Natural where ... N a - N b = let d = a - b in if d >= 0 then N d else error "Illegal Natural subtraction" -- one argument against Num ;-)
subtract (N a) (N b) = let d = a - b in if d >= 0 then Just $ N d else Nothing
.... Wolfram