1{-# LANGUAGE MonadComprehensions #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE OverloadedLists #-}
5module Main (main) where
8import qualified GHC.Exts as GHC
12#ifdef USE_STREAMLY_LIST
13import Data.Functor.Identity
14import Streamly.Internal.Data.List (List(..), pattern Cons, pattern Nil, ZipList(..),
15 fromZipList, toZipList)
16import qualified Streamly.Prelude as S
18import Prelude -- to suppress compiler warning
23pattern Nil <- [] where Nil = []
25pattern Cons :: a -> [a] -> [a]
26pattern Cons x xs = x : xs
29{-# COMPLETE Nil, Cons #-}
34#ifdef USE_STREAMLY_LIST
35 describe "OverloadedLists for 'SerialT Identity' type" $ do
36 it "Overloaded lists" $ do
37 ([1..3] :: SerialT Identity Int) `shouldBe` S.fromList [1..3]
38 GHC.toList ([1..3] :: SerialT Identity Int) `shouldBe` [1..3]
40 it "Show instance" $ do
41 show (S.fromList [1..3] :: SerialT Identity Int)
42 `shouldBe` "fromList [1,2,3]"
43 it "Read instance" $ do
44 (read "fromList [1,2,3]" :: SerialT Identity Int) `shouldBe` [1..3]
47 ([1,2,3] :: SerialT Identity Int) == [1,2,3] `shouldBe` True
49 it "Ord instance" $ do
50 ([1,2,3] :: SerialT Identity Int) > [1,2,1] `shouldBe` True
52 it "Monad comprehension" $ do
53 [(x,y) | x <- [1..2], y <- [1..2]] `shouldBe`
54 ([(1,1), (1,2), (2,1), (2,2)] :: SerialT Identity (Int, Int))
56 it "Foldable (sum)" $ sum ([1..3] :: SerialT Identity Int)
59 it "Traversable (mapM)" $
60 mapM return ([1..10] :: SerialT Identity Int)
61 `shouldReturn` [1..10]
63 describe "OverloadedStrings for 'SerialT Identity' type" $ do
64 it "overloaded strings" $ do
65 ("hello" :: SerialT Identity Char) `shouldBe` S.fromList "hello"
68 describe "OverloadedLists for List type" $ do
69 it "overloaded lists" $ do
70 ([1..3] :: List Int) `shouldBe` GHC.fromList [1..3]
71 GHC.toList ([1..3] :: List Int) `shouldBe` [1..3]
73 it "Construct empty list" $ (Nil :: List Int) `shouldBe` []
75 it "Construct a list" $ do
76 (Nil :: List Int) `shouldBe` []
77 ('x' `Cons` Nil) `shouldBe` ['x']
78 (1 `Cons` [2 :: Int]) `shouldBe` [1,2]
79 (1 `Cons` 2 `Cons` 3 `Cons` Nil :: List Int) `shouldBe` [1,2,3]
81 it "pattern matches" $ do
84 _ -> expectationFailure "not reached"
87 Cons 'x' Nil -> return ()
88 _ -> expectationFailure "not reached"
90 case [1..10 :: Int] of
94 _ -> expectationFailure "not reached"
96 case [1..10 :: Int] of
97 x `Cons` y `Cons` xs -> do
100 xs `shouldBe` [3..10]
101 _ -> expectationFailure "not reached"
103 it "Show instance" $ do
104 show ([1..3] :: List Int) `shouldBe`
105#ifdef USE_STREAMLY_LIST
106 "List {toSerial = fromList [1,2,3]}"
111 it "Read instance" $ do
113#ifdef USE_STREAMLY_LIST
114 "List {toSerial = fromList [1,2,3]}"
118 :: List Int) `shouldBe` [1..3]
120 it "Eq instance" $ do
121 ([1,2,3] :: List Int) == [1,2,3] `shouldBe` True
123 it "Ord instance" $ do
124 ([1,2,3] :: List Int) > [1,2,1] `shouldBe` True
126 it "Monad comprehension" $ do
127 [(x,y) | x <- [1..2], y <- [1..2]] `shouldBe`
128 ([(1,1), (1,2), (2,1), (2,2)] :: List (Int, Int))
130 it "Foldable (sum)" $ sum ([1..3] :: List Int) `shouldBe` 6
132 it "Traversable (mapM)" $
133 mapM return ([1..10] :: List Int)
134 `shouldReturn` [1..10]
136 describe "OverloadedStrings for List type" $ do
137 it "overloaded strings" $ do
138 ("hello" :: List Char) `shouldBe` GHC.fromList "hello"
140 it "pattern matches" $ do
141#if __GLASGOW_HASKELL__ >= 802
144 case "" :: List Char of
147 _ -> expectationFailure "not reached"
150 Cons x Nil -> x `shouldBe` 'a'
151 _ -> expectationFailure "not reached"
153 case "hello" <> "world" of
154 Cons x1 (Cons x2 xs) -> do
157 xs `shouldBe` "lloworld"
158 _ -> expectationFailure "not reached"
160#ifdef USE_STREAMLY_LIST
161 describe "OverloadedLists for ZipList type" $ do
162 it "overloaded lists" $ do
163 ([1..3] :: ZipList Int) `shouldBe` GHC.fromList [1..3]
164 GHC.toList ([1..3] :: ZipList Int) `shouldBe` [1..3]
167 toZipList (Nil :: List Int) `shouldBe` []
168 toZipList ('x' `Cons` Nil) `shouldBe` ['x']
169 toZipList (1 `Cons` [2 :: Int]) `shouldBe` [1,2]
170 toZipList (1 `Cons` 2 `Cons` 3 `Cons` Nil :: List Int) `shouldBe` [1,2,3]
172 it "fromZipList" $ do
173 case fromZipList [] of
175 _ -> expectationFailure "not reached"
177 case fromZipList ['x'] of
178 Cons 'x' Nil -> return ()
179 _ -> expectationFailure "not reached"
181 case fromZipList [1..10 :: Int] of
184 xs `shouldBe` [2..10]
185 _ -> expectationFailure "not reached"
187 case fromZipList [1..10 :: Int] of
188 x `Cons` y `Cons` xs -> do
191 xs `shouldBe` [3..10]
192 _ -> expectationFailure "not reached"
194 it "Show instance" $ do
195 show ([1..3] :: ZipList Int) `shouldBe`
196 "ZipList {toZipSerial = fromList [1,2,3]}"
198 it "Read instance" $ do
199 (read "ZipList {toZipSerial = fromList [1,2,3]}" :: ZipList Int)
202 it "Eq instance" $ do
203 ([1,2,3] :: ZipList Int) == [1,2,3] `shouldBe` True
205 it "Ord instance" $ do
206 ([1,2,3] :: ZipList Int) > [1,2,1] `shouldBe` True
208 it "Foldable (sum)" $ sum ([1..3] :: ZipList Int) `shouldBe` 6
210 it "Traversable (mapM)" $
211 mapM return ([1..10] :: ZipList Int)
212 `shouldReturn` [1..10]
214 it "Applicative Zip" $ do
215 (,) <$> "abc" <*> [1..3] `shouldBe`
216 ([('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