Hoon101 Week 2 Assignment in "Haskell"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.2KB

  1. {-# OPTIONS_GHC -fno-warn-missing-methods #-}
  2. {-# LANGUAGE MultiParamTypeClasses #-}
  3. {-# LANGUAGE FunctionalDependencies #-}
  4. {-# LANGUAGE FlexibleInstances #-}
  5. {-# LANGUAGE UndecidableInstances #-}
  6. nil = undefined
  7. data True
  8. data False
  9. data S n
  10. data Z
  11. data Nil
  12. data Cons h t
  13. data IsCell
  14. data IsOddAtom
  15. data IsEvenAtom
  16. class Not t b | t -> b
  17. instance Not True False
  18. instance Not False True
  19. class And a b r | a b -> r
  20. instance And True True True
  21. instance And True False False
  22. instance And False True False
  23. instance And False False False
  24. class If c t f r | c t f -> r
  25. instance If True t f t
  26. instance If False t f f
  27. class IsEven a b | a -> b
  28. instance IsEven Z True
  29. instance IsEven (S Z) False
  30. instance (IsEven n r)
  31. => IsEven (S (S n)) r
  32. instance IsEven (Cons xs x) False
  33. class Wutpam t b | t -> b
  34. instance Wutpam Z True
  35. instance Wutpam (S n) True
  36. instance Wutpam Nil False
  37. instance Wutpam (Cons x xs) False
  38. class Wutket t b | t -> b
  39. instance (Wutpam t b, Not b r)
  40. => Wutket t r
  41. class Solution n r | n -> r
  42. where solution :: n -> r
  43. instance ( Wutket n c
  44. , Not c a
  45. , IsEven n m
  46. , If m IsEvenAtom IsOddAtom e
  47. , If c IsCell e o
  48. )
  49. => Solution n o where solution = nil