--


data Day = Sun | Mon | Tue | Wed | Thu | Fri | Sat
   deriving Eq

valday 0 = Sun
valday 1 = Mon
valday 2 = Tue
valday 3 = Wed
valday 4 = Thu
valday 5 = Fri
valday 6 = Sat

dayvalA x =
  case x of
    Sun -> 0
    Mon -> 1
    Tue -> 2
    Wed -> 3 ; Thu -> 4 ; Fri -> 5
    Sat -> 6

dayval Sun = 0
dayval Mon = 1
dayval Tue = 2
dayval Wed = 3
dayval Thu = 4
dayval Fri = 5
dayval Sat = 6

dayvalB :: Day -> Int
dayvalB x =
  let (d,n) = head (filter (\(d,n)->d==x)
          (zip [Sun,Mon,Tue,Wed,Thu,Fri,Sat]
               [0..]))
  in n

dayafter d =
  valday (((dayval d) + 1) `mod` 7)


data Move = Paper | Rock | Scissors

beats :: Move -> Move
beats Paper = Scissors
beats Rock = Paper
beats Scissors = Rock


-- data Bool = True | False

data Direction = North | East | South | West


data Tagger = Tagn Int | Tagb  Bool

number (Tagn n) = n

boolean (Tagb b) = b

isNum (Tagn _) = True
isNum (Tagb _) = False

data Temp = Celsius  Float
          | Fahrenheit  Float
          | Kelvin  Float

toKelvin :: Temp -> Temp
toKelvin (Celsius c) = Kelvin(c + 272.0)
toKelvin (Fahrenheit f) =
      Kelvin( (f - 32.0) * (5.0/9.0) + 272.0 )
toKelvin (Kelvin k) = Kelvin k

data Shape = Rectangle Float Float
           | Ellipse Float Float
           | RtTriangle Float Float
           | Polygon [ (Float,Float) ]
  deriving Show

circle radius = Ellipse radius radius
square side = Rectangle side side

area :: Shape -> Float

area (Rectangle s1 s2)  = s1 * s2
area (Ellipse r1 r2)    =  pi * r1 * r2
area (RtTriangle s1 s2) = (s1 *s2) / 2
area (Polygon (v1:pts)) =  polyArea pts
   where polyArea :: [ (Float,Float) ] -> Float
         polyArea (v2 : v3 : vs) = triArea v1 v2 v3 +
                                   polyArea (v3:vs)
         polyArea _ = 0

triArea v1 v2 v3 =
  let a = distBetween v1 v2
      b = distBetween v2 v3
      c = distBetween v3 v1
      s = 0.5*(a+b+c)
  in sqrt (s*(s-a)*(s-b)*(s-c))


distBetween (x1,y1) (x2,y2)
 = sqrt ((x1-x2)^2 + (y1-y2)^2)


--