Skip to content

Instantly share code, notes, and snippets.

@jakobw
Created February 18, 2012 13:51
Show Gist options
  • Save jakobw/1859340 to your computer and use it in GitHub Desktop.
Save jakobw/1859340 to your computer and use it in GitHub Desktop.
1.2
-- Probeklausur 1.2
data N = Zero | S (N) deriving (Show) -- natürliche Zahlen
data Z = Z (N,N) deriving (Show) -- ganze Zahlen
class Rechnen a where
add :: a -> a -> a
instance Rechnen N where
add m Zero = m
add m (S (n)) = S (add m n)
instance Rechnen Z where
add (Z (m1, n1)) (Z (m2, n2)) = Z (add m1 m2, add n1 n2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment