From Danny, 3 Months ago, written in Plain Text.
This paste will cross the great divide in 7 Months.
Embed
  1. module HW1types where
  2.  
  3. import Data.List (nub,sort)
  4.  
  5. type Node  = Int
  6. type Edge  = (Node,Node)
  7. type Graph = [Edge]
  8. type Path  = [Node]
  9. type Bag a = [(a,Int)]
  10.  
  11. norm :: Ord a => [a] -> [a]
  12. norm = sort . nub
  13.  
  14. nullList  = []
  15. list = [2,3,3,5,7,7,7,8]
  16. bag1 = [(5,1),(7,3),(2,1),(3,2),(8,1)]
  17. bag2 = [(5,1),(3,6),(1,0),(8,7),(4,1)]
  18.  
  19. ins :: Eq a  => a -> Bag a -> Bag a
  20. ins x []     = [(x,1)]
  21. ins x (y:ys) = if x == fst y
  22.                    then (x,succ(snd y)):ys
  23.                else y : (ins x ys)
  24.  
  25. del :: Eq a  => a -> Bag a -> Bag a
  26. del a []     = []
  27. del a (x:xs) = if a == fst x
  28.                then (a,pred(snd x)):xs
  29.                else x : (del a xs)
  30.  
  31.