|
|
@@ -0,0 +1,61 @@ |
|
|
|
{-# OPTIONS_GHC -fno-warn-missing-methods #-} |
|
|
|
{-# LANGUAGE MultiParamTypeClasses #-} |
|
|
|
{-# LANGUAGE FunctionalDependencies #-} |
|
|
|
{-# LANGUAGE FlexibleInstances #-} |
|
|
|
{-# LANGUAGE UndecidableInstances #-} |
|
|
|
|
|
|
|
nil = undefined |
|
|
|
|
|
|
|
data True |
|
|
|
data False |
|
|
|
|
|
|
|
data S n |
|
|
|
data Z |
|
|
|
|
|
|
|
data Nil |
|
|
|
data Cons h t |
|
|
|
|
|
|
|
data IsCell |
|
|
|
data IsOddAtom |
|
|
|
data IsEvenAtom |
|
|
|
|
|
|
|
class Not t b | t -> b |
|
|
|
instance Not True False |
|
|
|
instance Not False True |
|
|
|
|
|
|
|
class And a b r | a b -> r |
|
|
|
instance And True True True |
|
|
|
instance And True False False |
|
|
|
instance And False True False |
|
|
|
instance And False False False |
|
|
|
|
|
|
|
class If c t f r | c t f -> r |
|
|
|
instance If True t f t |
|
|
|
instance If False t f f |
|
|
|
|
|
|
|
class IsEven a b | a -> b |
|
|
|
instance IsEven Z True |
|
|
|
instance IsEven (S Z) False |
|
|
|
instance (IsEven n r) |
|
|
|
=> IsEven (S (S n)) r |
|
|
|
instance IsEven (Cons xs x) False |
|
|
|
|
|
|
|
class Wutpam t b | t -> b |
|
|
|
instance Wutpam Z True |
|
|
|
instance Wutpam (S n) True |
|
|
|
instance Wutpam Nil False |
|
|
|
instance Wutpam (Cons x xs) False |
|
|
|
|
|
|
|
class Wutket t b | t -> b |
|
|
|
instance (Wutpam t b, Not b r) |
|
|
|
=> Wutket t r |
|
|
|
|
|
|
|
class Solution n r | n -> r |
|
|
|
where solution :: n -> r |
|
|
|
instance ( Wutket n c |
|
|
|
, Not c a |
|
|
|
, IsEven n m |
|
|
|
, If m IsEvenAtom IsOddAtom e |
|
|
|
, If c IsCell e o |
|
|
|
) |
|
|
|
=> Solution n o where solution = nil |