Parcourir la Source

provide a Seq instance for the prelude list.

Lucas Stadler 11 ans auparavant
Parent
commit
def0a950d7
1 fichiers modifiés avec 14 ajouts et 0 suppressions
  1. 14 0
      hs/DataStructures.hs

+ 14 - 0
hs/DataStructures.hs

@ -75,6 +75,20 @@ reverse s = rev s nil
75 75
                  Nothing -> nil
76 76
                  Just x -> rev (rest l) $ cons x r
77 77
78
instance Seq [] where
79
    first [] = Nothing
80
    first (x:_) = Just x
81
82
    cons x xs = x:xs
83
84
    nil = []
85
86
    rest [] = []
87
    rest (_:xs) = xs
88
89
    isEmpty [] = True
90
    isEmpty _ = False
91
78 92
data List a = Nil | Cons a (List a) deriving Show
79 93
80 94
-- first and cons are O(1), everything else is O(n)