1{-# LANGUAGE MonadComprehensions #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE OverloadedLists #-}
5module Main (main) where
8import qualified GHC.Exts as GHC
10#ifdef USE_STREAMLY_LIST
11import Data.Functor.Identity
12import Streamly.Internal.Data.List (List(..), pattern Cons, pattern Nil, ZipList(..),
13 fromZipList, toZipList)
14import Streamly.Prelude (SerialT)
15import qualified Streamly.Prelude as S
17import Prelude -- to suppress compiler warning
22pattern Nil <- [] where Nil = []
24pattern Cons :: a -> [a] -> [a]
25pattern Cons x xs = x : xs
28{-# COMPLETE Nil, Cons #-}
32#ifdef USE_STREAMLY_LIST
33moduleName = "Data.List+Data.List.Base"
35moduleName = "Data.List.Base"
40 describe moduleName $ do
41#ifdef USE_STREAMLY_LIST
42 describe "OverloadedLists for 'SerialT Identity' type" $ do
43 it "Overloaded lists" $ do
44 ([1..3] :: SerialT Identity Int) `shouldBe` S.fromList [1..3]
45 GHC.toList ([1..3] :: SerialT Identity Int) `shouldBe` [1..3]
47 it "Show instance" $ do
48 show (S.fromList [1..3] :: SerialT Identity Int)
49 `shouldBe` "fromList [1,2,3]"
50 it "Read instance" $ do
51 (read "fromList [1,2,3]" :: SerialT Identity Int) `shouldBe` [1..3]
54 ([1,2,3] :: SerialT Identity Int) == [1,2,3] `shouldBe` True
56 it "Ord instance" $ do
57 ([1,2,3] :: SerialT Identity Int) > [1,2,1] `shouldBe` True
59 it "Monad comprehension" $ do
60 [(x,y) | x <- [1..2], y <- [1..2]] `shouldBe`
61 ([(1,1), (1,2), (2,1), (2,2)] :: SerialT Identity (Int, Int))
63 it "Foldable (sum)" $ sum ([1..3] :: SerialT Identity Int)
66 it "Traversable (mapM)" $
67 mapM return ([1..10] :: SerialT Identity Int)
68 `shouldReturn` [1..10]
70 describe "OverloadedStrings for 'SerialT Identity' type" $ do
71 it "overloaded strings" $ do
72 ("hello" :: SerialT Identity Char) `shouldBe` S.fromList "hello"
75 describe "OverloadedLists for List type" $ do
76 it "overloaded lists" $ do
77 ([1..3] :: List Int) `shouldBe` GHC.fromList [1..3]
78 GHC.toList ([1..3] :: List Int) `shouldBe` [1..3]
80 it "Construct empty list" $ (Nil :: List Int) `shouldBe` []
82 it "Construct a list" $ do
83 (Nil :: List Int) `shouldBe` []
84 ('x' `Cons` Nil) `shouldBe` ['x']
85 (1 `Cons` [2 :: Int]) `shouldBe` [1,2]
86 (1 `Cons` 2 `Cons` 3 `Cons` Nil :: List Int) `shouldBe` [1,2,3]
88 it "pattern matches" $ do
91 _ -> expectationFailure "not reached"
94 Cons 'x' Nil -> return ()
95 _ -> expectationFailure "not reached"
97 case [1..10 :: Int] of
100 xs `shouldBe` [2..10]
101 _ -> expectationFailure "not reached"
103 case [1..10 :: Int] of
104 x `Cons` y `Cons` xs -> do
107 xs `shouldBe` [3..10]
108 _ -> expectationFailure "not reached"
110 it "Show instance" $ do
111 show ([1..3] :: List Int) `shouldBe`
112#ifdef USE_STREAMLY_LIST
113 "List {toSerial = fromList [1,2,3]}"
118 it "Read instance" $ do
120#ifdef USE_STREAMLY_LIST
121 "List {toSerial = fromList [1,2,3]}"
125 :: List Int) `shouldBe` [1..3]
127 it "Eq instance" $ do
128 ([1,2,3] :: List Int) == [1,2,3] `shouldBe` True
130 it "Ord instance" $ do
131 ([1,2,3] :: List Int) > [1,2,1] `shouldBe` True
133 it "Monad comprehension" $ do
134 [(x,y) | x <- [1..2], y <- [1..2]] `shouldBe`
135 ([(1,1), (1,2), (2,1), (2,2)] :: List (Int, Int))
137 it "Foldable (sum)" $ sum ([1..3] :: List Int) `shouldBe` 6
139 it "Traversable (mapM)" $
140 mapM return ([1..10] :: List Int)
141 `shouldReturn` [1..10]
143 describe "OverloadedStrings for List type" $ do
144 it "overloaded strings" $ do
145 ("hello" :: List Char) `shouldBe` GHC.fromList "hello"
147 it "pattern matches" $ do
150 _ -> expectationFailure "not reached"
153 Cons x Nil -> x `shouldBe` 'a'
154 _ -> expectationFailure "not reached"
156 case "hello" <> "world" of
157 Cons x1 (Cons x2 xs) -> do
160 xs `shouldBe` "lloworld"
161 _ -> expectationFailure "not reached"
163#ifdef USE_STREAMLY_LIST
164 describe "OverloadedLists for ZipList type" $ do
165 it "overloaded lists" $ do
166 ([1..3] :: ZipList Int) `shouldBe` GHC.fromList [1..3]
167 GHC.toList ([1..3] :: ZipList Int) `shouldBe` [1..3]
170 toZipList (Nil :: List Int) `shouldBe` []
171 toZipList ('x' `Cons` Nil) `shouldBe` ['x']
172 toZipList (1 `Cons` [2 :: Int]) `shouldBe` [1,2]
173 toZipList (1 `Cons` 2 `Cons` 3 `Cons` Nil :: List Int) `shouldBe` [1,2,3]
175 it "fromZipList" $ do
176 case fromZipList [] of
178 _ -> expectationFailure "not reached"
180 case fromZipList ['x'] of
181 Cons 'x' Nil -> return ()
182 _ -> expectationFailure "not reached"
184 case fromZipList [1..10 :: Int] of
187 xs `shouldBe` [2..10]
188 _ -> expectationFailure "not reached"
190 case fromZipList [1..10 :: Int] of
191 x `Cons` y `Cons` xs -> do
194 xs `shouldBe` [3..10]
195 _ -> expectationFailure "not reached"
197 it "Show instance" $ do
198 show ([1..3] :: ZipList Int) `shouldBe`
199 "ZipList {toZipSerial = fromList [1,2,3]}"
201 it "Read instance" $ do
202 (read "ZipList {toZipSerial = fromList [1,2,3]}" :: ZipList Int)
205 it "Eq instance" $ do
206 ([1,2,3] :: ZipList Int) == [1,2,3] `shouldBe` True
208 it "Ord instance" $ do
209 ([1,2,3] :: ZipList Int) > [1,2,1] `shouldBe` True
211 it "Foldable (sum)" $ sum ([1..3] :: ZipList Int) `shouldBe` 6
213 it "Traversable (mapM)" $
214 mapM return ([1..10] :: ZipList Int)
215 `shouldReturn` [1..10]
217 it "Applicative Zip" $ do
218 (,) <$> "abc" <*> [1..3] `shouldBe`
219 ([('a',1),('b',2),('c',3)] :: ZipList (Char, Int))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list