data Tree a = L | N a (Tree a) (Tree a) deriving Show

sumTree L = 0
sumTree (N x l r) = x + (sumTree l) + (sumTree r)

inorder :: Tree a -> [a]
inorder L = []
inorder (N x l r) = (inorder l) ++ [x] ++ (inorder r)

data List a = Nil | Cons a (List a) deriving Show
data StrangeList a b = StrangeNil | StrangeCons a (StrangeList b a) deriving Show

list2mylist [] = Nil
list2mylist (x:xs) = Cons x (list2mylist xs)

mylist2list Nil = []
mylist2list (Cons x xs) = x:mylist2list xs

mylen, mylen2 :: List a -> Int
mylen Nil = 0
mylen (Cons x xs) = 1 + mylen xs

mylen2 xs = length (mylist2list xs)

data Nats = Zero | Succ Nats deriving Show

three = Succ (Succ (Succ Zero))

nats2int Zero = 0
nats2int (Succ x) = 1 + nats2int x

int2nats 0 = Zero
int2nats (n+1) = Succ (int2nats n)
int2nats _ = error "Come on ... I'm nuts!"

square :: Float -> Float
square = \x -> x * x

data Point a = Pair a a
  deriving Show

dist :: Point Float -> Point Float -> Float
dist (Pair x1 y1) (Pair x2 y2) = sqrt ((square (x1-x2)) + (square (y1-y2)))

shift :: Float -> Float -> Point Float -> Point Float
shift dx dy (Pair x y) = Pair (x+dx) (y+dy)

data Color = Red | Green | Blue | Orange deriving Show
complement Red = Green
complement Green = Red
complement Blue = Orange
complement Orange = Blue

