Skip to content

Commit

Permalink
Update library to be v0.14.0 compatible (#48)
Browse files Browse the repository at this point in the history
* Update source code to v0.14.0

* Update dependencies to v0.14.0 compatible versions; drop proxy

* Update code to have kind signatures and use both proxy types

* Update imports and exports

* Update documentation to use Proxy type instead of SProxy and FProxy

* Use Proxy type everywhere

* Update PS version in CI to v0.14.0

* Update pulp and psa to latest versions

* Remove usage of FProxy in VariantF rows

* Update Readme: remove SProxy and FProxy

* Include Proxy import in readme

* Remove rather than deprecate FProxy

Co-authored-by: Nick Scheel <11701520+MonoidMusician@users.noreply.github.com>
  • Loading branch information
JordanMartinez and MonoidMusician committed Mar 2, 2021
1 parent 31e6203 commit 6907b86
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 185 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -3,7 +3,7 @@ dist: trusty
sudo: required
node_js: stable
before_script:
- TAG=v0.12.3
- TAG=v0.14.0
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
- chmod a+x $HOME/purescript
Expand Down
37 changes: 18 additions & 19 deletions README.md
Expand Up @@ -83,22 +83,24 @@ This library just uses the same structural row system that we use with records
We lift values into `Variant` with `inj` by specifying a _tag_.

```purescript
import Type.Proxy (Proxy(..))
someFoo :: forall v. Variant (foo :: Int | v)
someFoo = inj (SProxy :: SProxy "foo") 42
someFoo = inj (Proxy :: Proxy "foo") 42
```

`SProxy` is just a way to tell the compiler what our tag is at the type level.
`Proxy` is just a way to tell the compiler what our tag is at the type level.
I can stamp out a bunch of these with different labels:

```purescript
someFoo :: forall v. Variant (foo :: Int | v)
someFoo = inj (SProxy :: SProxy "foo") 42
someFoo = inj (Proxy :: Proxy "foo") 42
someBar :: forall v. Variant (bar :: Boolean | v)
someBar = inj (SProxy :: SProxy "bar") true
someBar = inj (Proxy :: Proxy "bar") true
someBaz :: forall v. Variant (baz :: String | v)
someBaz = inj (SProxy :: SProxy "baz") "Baz"
someBaz = inj (Proxy :: Proxy "baz") "Baz"
```

We can try to extract a value from this via `on`, which takes a function to
Expand All @@ -107,7 +109,7 @@ case of failure.

```purescript
fooToString :: forall v. Variant (foo :: Int | v) -> String
fooToString = on (SProxy :: SProxy "foo") show (\_ -> "not foo")
fooToString = on (Proxy :: Proxy "foo") show (\_ -> "not foo")
fooToString someFoo == "42"
fooToString someBar == "not foo"
Expand All @@ -117,9 +119,9 @@ We can chain usages of `on` and terminate it with `case_` (for compiler-checked
exhaustivity) or `default` (to provide a default value in case of failure).

```purescript
_foo = SProxy :: SProxy "foo"
_bar = SProxy :: SProxy "bar"
_baz = SProxy :: SProxy "baz"
_foo = Proxy :: Proxy "foo"
_bar = Proxy :: Proxy "bar"
_baz = Proxy :: Proxy "baz"
allToString :: Variant (foo :: Int, bar :: Boolean, baz :: String) -> String
allToString =
Expand Down Expand Up @@ -182,17 +184,14 @@ which lives in `Data.Functor.Variant`. `VariantF` is just like `Variant`,
except it's indexed by things of kind `Type -> Type`.

```purescript
someFoo :: forall v. VariantF (foo :: FProxy Maybe | v) Int
someFoo = inj (SProxy :: SProxy "foo") (Just 42)
someFoo :: forall v. VariantF (foo :: Maybe | v) Int
someFoo = inj (Proxy :: Proxy "foo") (Just 42)
someBar :: forall v. VariantF (bar :: FProxy (Tuple String) | v) Int
someBar = inj (SProxy :: SProxy "bar") (Tuple "bar" 42)
someBar :: forall v. VariantF (bar :: Tuple String | v) Int
someBar = inj (Proxy :: Proxy "bar") (Tuple "bar" 42)
someBaz :: forall v a. VariantF (baz :: FProxy (Either String) | v) a
someBaz = inj (SProxy :: SProxy "baz") (Left "Baz")
someBaz :: forall v a. VariantF (baz :: Either String | v) a
someBaz = inj (Proxy :: Proxy "baz") (Left "Baz")
```

`VariantF` supports all the same combinators as `Variant`. We need to use
`FProxy` in the types, however, because the row machinery in PuresScript
is not poly-kinded. `FProxy` lets us talk about functors, but trick the
type system into thinking they are the expected kind.
`VariantF` supports all the same combinators as `Variant`.
23 changes: 11 additions & 12 deletions bower.json
Expand Up @@ -23,19 +23,18 @@
"test"
],
"dependencies": {
"purescript-prelude": "^4.0.0",
"purescript-tuples": "^5.0.0",
"purescript-unsafe-coerce": "^4.0.0",
"purescript-partial": "^2.0.0",
"purescript-maybe": "^4.0.0",
"purescript-lists": "^5.0.0",
"purescript-record": "^2.0.0",
"purescript-enums": "^4.0.0",
"purescript-proxy": "^3.0.0"
"purescript-prelude": "^5.0.0",
"purescript-tuples": "^6.0.0",
"purescript-unsafe-coerce": "^5.0.0",
"purescript-partial": "^3.0.0",
"purescript-maybe": "^5.0.0",
"purescript-lists": "^6.0.0",
"purescript-record": "^3.0.0",
"purescript-enums": "^5.0.0"
},
"devDependencies": {
"purescript-console": "^4.0.0",
"purescript-assert": "^4.0.0",
"purescript-either": "^4.0.0"
"purescript-console": "^5.0.0",
"purescript-assert": "^5.0.0",
"purescript-either": "^5.0.0"
}
}
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -5,7 +5,7 @@
"test": "pulp test"
},
"devDependencies": {
"pulp": "^12.2.0",
"purescript-psa": "^0.6.0"
"pulp": "^15.0.0",
"purescript-psa": "^0.8.2"
}
}

0 comments on commit 6907b86

Please sign in to comment.