mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-11-28 19:13:02 +03:00
Merge pull request #914 from stefan-hoeck/lazy-list-impls
Eq, Ord, and Show instances for LazyList
This commit is contained in:
commit
96257f23c3
@ -12,6 +12,34 @@ data LazyList : Type -> Type where
|
||||
|
||||
--- Interface implementations ---
|
||||
|
||||
public export
|
||||
Eq a => Eq (LazyList a) where
|
||||
[] == [] = True
|
||||
x :: xs == y :: ys = x == y && xs == ys
|
||||
_ == _ = False
|
||||
|
||||
public export
|
||||
Ord a => Ord (LazyList a) where
|
||||
compare [] [] = EQ
|
||||
compare [] (x :: xs) = LT
|
||||
compare (x :: xs) [] = GT
|
||||
compare (x :: xs) (y ::ys)
|
||||
= case compare x y of
|
||||
EQ => compare xs ys
|
||||
c => c
|
||||
|
||||
export
|
||||
Show a => Show (LazyList a) where
|
||||
show [] = "[]"
|
||||
show (h :: t) = "[" ++ show' "" h t ++ "]"
|
||||
where
|
||||
-- Idris didn't like the lazyness involved when using the
|
||||
-- same implementation as for `List`, therefore, this was
|
||||
-- adjusted to first force the head and tail of the list.
|
||||
show' : String -> a -> LazyList a -> String
|
||||
show' acc h Nil = acc ++ show h
|
||||
show' acc h (x :: xs) = show' (acc ++ show h ++ ", ") x xs
|
||||
|
||||
public export
|
||||
Semigroup (LazyList a) where
|
||||
[] <+> ys = ys
|
||||
|
Loading…
Reference in New Issue
Block a user