File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change
1
+ module Type.Row.Effect.Equality
2
+ ( class EffectRowEquals
3
+ , to
4
+ , from
5
+ , effTo
6
+ , effFrom
7
+ ) where
8
+
9
+ -- | This type class asserts that effect rows `a` and `b` are equal.
10
+ -- |
11
+ -- | The functional dependencies and the single instance below will force the
12
+ -- | two type arguments to unify when either one is known.
13
+ -- |
14
+ -- | Note: any instance will necessarily ovelap with `refl` below, so instances
15
+ -- | of this class should not be defined in libraries.
16
+ class EffectRowEquals (a :: # Effect ) (b :: # Effect ) | a -> b , b -> a where
17
+ to :: forall r . r a -> r b
18
+ from :: forall r . r b -> r a
19
+
20
+ instance refl :: EffectRowEquals a a where
21
+ to a = a
22
+ from a = a
23
+
24
+ newtype Flipmode e a eff = Flipmode (e eff a )
25
+
26
+ unflip :: forall e a eff . Flipmode e a eff -> e eff a
27
+ unflip (Flipmode e) = e
28
+
29
+ -- | A version of `to` that can be applied to types like `Eff`, `Aff`, etc.
30
+ effTo :: forall e a b x . EffectRowEquals a b => e a x -> e b x
31
+ effTo e = unflip (to (Flipmode e))
32
+
33
+ -- | A version of `from` that can be applied to types like `Eff`, `Aff`, etc.
34
+ effFrom :: forall e a b x . EffectRowEquals a b => e b x -> e a x
35
+ effFrom e = unflip (from (Flipmode e))
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import Control.Monad.Eff (Eff)
5
5
import Control.Monad.Eff.Console (CONSOLE , log )
6
6
import Data.Newtype (class Newtype , unwrap )
7
7
import Type.Equality (class TypeEquals , to , from )
8
+ import Type.Row.Effect.Equality as REE
8
9
9
10
newtype RecordNewtype = RecordNewtype
10
11
{ message :: String }
@@ -15,5 +16,11 @@ instance newtypeRecordNewtype ::
15
16
wrap = RecordNewtype <<< to
16
17
unwrap (RecordNewtype rec) = from rec
17
18
19
+ class Foo f where
20
+ foo :: String -> f Unit
21
+
22
+ instance fooEff :: REE.EffectRowEquals eff (console :: CONSOLE | e ) => Foo (Eff eff ) where
23
+ foo = REE .effFrom <<< log
24
+
18
25
main :: Eff (console :: CONSOLE ) Unit
19
- main = log (unwrap (RecordNewtype { message: " Done" })).message
26
+ main = foo (unwrap (RecordNewtype { message: " Done" })).message
You can’t perform that action at this time.
0 commit comments