Skip to content

Commit c083da6

Browse files
authored
Generalize Exists to hold non-Type-kinded types (#14)
1 parent 435ca71 commit c083da6

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Breaking changes:
1919

2020
New features:
2121
- Added roles declarations to allow safe coercions (#9)
22+
- Generalized `Exists` to hold non-`Type`-kinded types (#14)
2223

2324
Bugfixes:
2425

src/Data/Exists.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Data.Exists where
22

33
import Unsafe.Coerce (unsafeCoerce)
44

5-
-- | This type constructor can be used to existentially quantify over a type of kind `Type`.
5+
-- | This type constructor can be used to existentially quantify over a type.
66
-- |
77
-- | Specifically, the type `Exists f` is isomorphic to the existential type `exists a. f a`.
88
-- |
@@ -24,7 +24,7 @@ import Unsafe.Coerce (unsafeCoerce)
2424
-- | ```purescript
2525
-- | type Stream a = Exists (StreamF a)
2626
-- | ```
27-
foreign import data Exists :: (Type -> Type) -> Type
27+
foreign import data Exists :: forall k. (k -> Type) -> Type
2828

2929
type role Exists representational
3030

test/Test/Main.purs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,24 @@ head = runExists head'
2525
head' :: forall s. StreamF a s -> a
2626
head' (StreamF s f) = snd (f s)
2727

28+
data Maybe a = Nothing | Just a
29+
30+
count :: forall a. Maybe a -> Int
31+
count Nothing = 0
32+
count _ = 1
33+
34+
data FooF f = FooF (forall a. f a -> Int) (f String)
35+
36+
type Foo = Exists FooF
37+
38+
foo :: Foo
39+
foo = mkExists $ FooF count (Just "test")
40+
41+
x :: Int
42+
x = runExists runFooF foo
43+
where
44+
runFooF :: forall f. FooF f -> Int
45+
runFooF (FooF f fStr) = f fStr
46+
2847
main :: Effect Unit
2948
main = logShow $ head nats

0 commit comments

Comments
 (0)