Good evening, the following says it all:
~% /var/tmp/ghc/bin/ghci /tmp/foo.hs ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.4.20050215, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help. Loading package base-1.0 ... linking ... done. Compiling Main ( /tmp/foo.hs, interpreted ) /tmp/foo.hs:64:6: No instance for (Show c) arising from use of `show' at /tmp/foo.hs:64:6-9 Probable fix:*** Exception: typecheck/TcSimplify.lhs:2389:8-82: Non-exhaustive patterns in function add_ors > The "work-in-progress" source causing it is attached. Happy hacking, Remi -- Nobody can be exactly like me. Even I have trouble doing it.
{-# OPTIONS -fglasgow-exts -fallow-undecidable-instances #-} -- static Peano constructors and numerals data Zero = Zero deriving Show data One = One deriving Show infixl 9 :@ data (Number a, Digit b) => a :@ b = a :@ b deriving Show class Digit a instance Digit Zero instance Digit One class Number a instance Number Zero instance Number One instance (Number a, Digit b) => Number (a :@ b) --- Pretty printing of numbers --- class PrettyNum a where prettyNum :: a -> String instance PrettyNum Zero where prettyNum _ = "0" instance PrettyNum One where prettyNum _ = "1" instance (Number a, Digit b, PrettyNum a, PrettyNum b) => PrettyNum (a :@ b) where prettyNum ~(a:@b) = prettyNum a ++ prettyNum b --- Digit addition --- class (Number a, Digit b, Number c) => AddDigit a b c | a b -> c where addDigit :: a -> b -> c addDigit = undefined instance Number a => AddDigit a Zero a instance AddDigit Zero One One instance AddDigit One One (One:@Zero) instance Number a => AddDigit (a:@Zero) One (a:@One) instance AddDigit a One a' => AddDigit (a:@One) One (a':@Zero) --- Addition --- class (Number a, Number b, Number c) => Add a b c | a b -> c where add :: a -> b -> c add = undefined instance Number n => Add n Zero n instance Add Zero One One instance Add One One (One:@One) instance Number n => Add (n:@Zero) One (n:@One) instance AddDigit n One r' => Add (n:@One) One (r':@Zero) instance (Number n1, Digit d1, Number n2, Digit n2 ,Add n1 n2 nr', AddDigit (d1:@nr') d2 r) => Add (n1:@d1) (n2:@d2) r foo = show $ add (One:@Zero) (One:@One)
_______________________________________________ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs