File tree Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ module Data.Eq1 where
2
+
3
+ import Prelude
4
+
5
+ class Eq1 f where
6
+ eq1 :: forall a . (Eq a ) => f a -> f a -> Boolean
Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ module Data.Functor.Mu
5
5
) where
6
6
7
7
import Prelude
8
+ import Data.TacitString as TS
9
+
10
+ import Data.Eq1
11
+ import Data.Ord1
8
12
9
13
-- | `Mu f` is the least fixed point of a functor `f`, when it exists.
10
14
data Mu f = In (f (Mu f ))
@@ -14,3 +18,18 @@ roll = In
14
18
15
19
unroll :: forall f . Mu f -> f (Mu f )
16
20
unroll (In x) = x
21
+
22
+ -- | To implement `Eq`, we require `f` to have higher-kinded equality.
23
+ instance eqMu :: (Eq1 f ) => Eq (Mu f ) where
24
+ eq (In x) (In y) = eq1 x y
25
+
26
+ -- | To implement `Ord`, we require `f` to have higher-kinded comparison.
27
+ instance ordMu :: (Eq1 f , Ord1 f ) => Ord (Mu f ) where
28
+ compare (In x) (In y) = compare1 x y
29
+
30
+ -- | `Show` is compositional, so we only `f` to be able to show a single layer of structure.
31
+ -- Therefore, there is no need for `Show1`; we use `TacitString` in order to prevent
32
+ -- extra quotes from appearing.
33
+ instance showMu :: (Show (f TS.TacitString ), Functor f ) => Show (Mu f ) where
34
+ show (In x) = show $ x <#> (show >>> TS .hush)
35
+
Original file line number Diff line number Diff line change
1
+ module Data.Ord1 where
2
+
3
+ import Prelude
4
+
5
+ class Ord1 f where
6
+ compare1 :: forall a . (Ord a ) => f a -> f a -> Ordering
Original file line number Diff line number Diff line change
1
+ module Data.TacitString
2
+ ( TacitString ()
3
+ , hush
4
+ ) where
5
+
6
+ import Prelude
7
+
8
+ newtype TacitString = TacitString String
9
+ instance showTacitString :: Show TacitString where
10
+ show (TacitString str) = str
11
+
12
+ hush :: String -> TacitString
13
+ hush = TacitString
You can’t perform that action at this time.
0 commit comments