Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,24 @@ on:
pull_request:
branches: [master]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: purescript-contrib/setup-purescript@main
with:
purescript: "unstable"
- uses: actions/checkout@v6

- uses: actions/setup-node@v2
- uses: actions/setup-node@v6
with:
node-version: "14.x"
node-version: "24"

- name: Install dependencies
run: |
npm install -g bower
npm install
bower install --production
run: npm install

- name: Build source
run: npm run-script build
run: npm run build

- name: Run tests
run: |
bower install
npm run-script test --if-present
- name: Check formatting
run: npm run format:check
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/.*
!/.gitignore
!/.github/
package-lock.json
!/.tidyrc.json
/package-lock.json
/spago.lock
/bower_components/
/node_modules/
/output/
package-lock.json
10 changes: 10 additions & 0 deletions .tidyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"importSort": "ide",
"importWrap": "source",
"indent": 2,
"operatorsFile": null,
"ribbon": 1,
"typeArrowPlacement": "first",
"unicode": "never",
"width": null
}
18 changes: 15 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [Unreleased](https://github.com/purescript/purescript-typelevel-prelude/compare/v7.0.1...HEAD)

Breaking changes:

Expand All @@ -12,13 +12,22 @@ Bugfixes:

Other improvements:

## [v7.0.1](https://github.com/purescript/purescript-typelevel-prelude/releases/tag/v7.0.1) - 2026-10-17

Other improvements:

- Migrate from Bower/Pulp to Spago and update CI (#76 by @thomashoneyman)
- Fix comment typos (#75 by @i-am-the-slime)

## [v7.0.0](https://github.com/purescript/purescript-typelevel-prelude/releases/tag/v7.0.0) - 2022-04-27

Breaking changes:

- Update project and deps to PureScript v0.15.0 (#72 by @JordanMartinez)
- Replaced polymorphic proxies with monomorphic `Proxy` (#72 by @JordanMartinez)

New features:

- Added `#` infix operator for `FLIP` (e.g. `Int # Maybe` == `Maybe Int`) (#73 by @JordanMartinez)

Bugfixes:
Expand All @@ -28,17 +37,20 @@ Other improvements:
## [v6.0.0](https://github.com/purescript/purescript-typelevel-prelude/releases/tag/v6.0.0) - 2021-02-26

Breaking changes:

- Added support for PureScript 0.14 and dropped support for all previous versions (#63)

New features:

- Replaced monomorphic proxies with `Type.Proxy.Proxy` and polymorphic variables and made `If` and `TypeEquals` polykinded (#64)
- Added `APPLY`/`$` and `FLIP` type aliases (#63)
- The type `Foo (Bar Baz)` is the same as `Foo $ Bar Baz`
- The type `Either a b` is the same as `FLIP Either b a`
- The type `Foo (Bar Baz)` is the same as `Foo $ Bar Baz`
- The type `Either a b` is the same as `FLIP Either b a`

Bugfixes:

Other improvements:

- Migrated CI to GitHub Actions and updated installation instructions to use Spago (#67)
- Added a changelog and pull request template (#68, #69)

Expand Down
22 changes: 0 additions & 22 deletions bower.json

This file was deleted.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"private": true,
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "pulp build -- --censor-lib --strict"
"build": "spago build",
"format": "purs-tidy format-in-place src && oxfmt --write .",
"format:check": "purs-tidy check src && oxfmt --check ."
},
"devDependencies": {
"pulp": "16.0.0-0",
"purescript-psa": "^0.8.2",
"rimraf": "^3.0.2"
"oxfmt": "^0.73.0",
"purescript": "^0.15.16",
"purs-tidy": "^0.11.1",
"spago": "^1.0.5"
}
}
16 changes: 16 additions & 0 deletions spago.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package:
name: typelevel-prelude
description: Types and kinds for basic type-level programming
build:
strict: true
pedanticPackages: true
publish:
version: 7.0.1
license: BSD-3-Clause
location:
githubOwner: purescript
githubRepo: purescript-typelevel-prelude
dependencies:
- prelude: ">=6.0.0 <7.0.0"
- type-equality: ">=4.0.1 <5.0.0"
workspace: {}
18 changes: 13 additions & 5 deletions src/Type/Data/Boolean.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,30 @@ module Type.Data.Boolean
, if_
) where

import Prim.Boolean (True, False)
import Prim.Boolean (False, True)
import Type.Proxy (Proxy(..))

-- | Class for reflecting a type level `Boolean` at the value level
class IsBoolean :: Boolean -> Constraint
class IsBoolean bool where
reflectBoolean :: Proxy bool -> Boolean

instance isBooleanTrue :: IsBoolean True where reflectBoolean _ = true
instance isBooleanFalse :: IsBoolean False where reflectBoolean _ = false
instance isBooleanTrue :: IsBoolean True where
reflectBoolean _ = true

instance isBooleanFalse :: IsBoolean False where
reflectBoolean _ = false

-- | Use a value level `Boolean` as a type-level `Boolean`
reifyBoolean :: forall r. Boolean -> (forall o. IsBoolean o => Proxy o -> r) -> r
reifyBoolean true f = f (Proxy :: Proxy True)
reifyBoolean false f = f (Proxy :: Proxy False)
reifyBoolean bool f = case bool of
true -> f (Proxy :: Proxy True)
false -> f (Proxy :: Proxy False)

-- | And two `Boolean` types together
class And :: Boolean -> Boolean -> Boolean -> Constraint
class And lhs rhs out | lhs rhs -> out

instance andTrue :: And True rhs rhs
instance andFalse :: And False rhs False

Expand All @@ -41,6 +46,7 @@ and _ _ = Proxy
-- | Or two `Boolean` types together
class Or :: Boolean -> Boolean -> Boolean -> Constraint
class Or lhs rhs output | lhs rhs -> output

instance orTrue :: Or True rhs True
instance orFalse :: Or False rhs rhs

Expand All @@ -50,6 +56,7 @@ or _ _ = Proxy
-- | Not a `Boolean`
class Not :: Boolean -> Boolean -> Constraint
class Not bool output | bool -> output

instance notTrue :: Not True False
instance notFalse :: Not False True

Expand All @@ -59,6 +66,7 @@ not _ = Proxy
-- | If - dispatch based on a boolean
class If :: forall k. Boolean -> k -> k -> k -> Constraint
class If bool onTrue onFalse output | bool onTrue onFalse -> output

instance ifTrue :: If True onTrue onFalse onTrue
instance ifFalse :: If False onTrue onFalse onFalse

Expand Down
24 changes: 16 additions & 8 deletions src/Type/Data/Ordering.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,37 @@ module Type.Data.Ordering
, equals
) where

import Prim.Ordering (LT, EQ, GT, Ordering) as PO
import Data.Ordering (Ordering(..))
import Type.Data.Boolean (True, False)
import Prim.Ordering (EQ, GT, LT, Ordering) as PO
import Type.Data.Boolean (False, True)
import Type.Proxy (Proxy(..))

-- | Class for reflecting a type level `Ordering` at the value level
class IsOrdering :: PO.Ordering -> Constraint
class IsOrdering ordering where
reflectOrdering :: Proxy ordering -> Ordering

instance isOrderingLT :: IsOrdering PO.LT where reflectOrdering _ = LT
instance isOrderingEQ :: IsOrdering PO.EQ where reflectOrdering _ = EQ
instance isOrderingGT :: IsOrdering PO.GT where reflectOrdering _ = GT
instance isOrderingLT :: IsOrdering PO.LT where
reflectOrdering _ = LT

instance isOrderingEQ :: IsOrdering PO.EQ where
reflectOrdering _ = EQ

instance isOrderingGT :: IsOrdering PO.GT where
reflectOrdering _ = GT

-- | Use a value level `Ordering` as a type-level `Ordering`
reifyOrdering :: forall r. Ordering -> (forall o. IsOrdering o => Proxy o -> r) -> r
reifyOrdering LT f = f (Proxy :: Proxy PO.LT)
reifyOrdering EQ f = f (Proxy :: Proxy PO.EQ)
reifyOrdering GT f = f (Proxy :: Proxy PO.GT)
reifyOrdering ordering f = case ordering of
LT -> f (Proxy :: Proxy PO.LT)
EQ -> f (Proxy :: Proxy PO.EQ)
GT -> f (Proxy :: Proxy PO.GT)

-- | Append two `Ordering` types together
-- | Reflective of the semigroup for value level `Ordering`
class Append :: PO.Ordering -> PO.Ordering -> PO.Ordering -> Constraint
class Append lhs rhs output | lhs -> rhs output

instance appendOrderingLT :: Append PO.LT rhs PO.LT
instance appendOrderingEQ :: Append PO.EQ rhs rhs
instance appendOrderingGT :: Append PO.GT rhs PO.GT
Expand All @@ -45,6 +52,7 @@ append _ _ = Proxy
-- | Invert an `Ordering`
class Invert :: PO.Ordering -> PO.Ordering -> Constraint
class Invert ordering result | ordering -> result

instance invertOrderingLT :: Invert PO.LT PO.GT
instance invertOrderingEQ :: Invert PO.EQ PO.EQ
instance invertOrderingGT :: Invert PO.GT PO.LT
Expand Down
17 changes: 9 additions & 8 deletions src/Type/Data/Symbol.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ module Type.Data.Symbol
, equals
) where

import Prim.Symbol (class Append, class Compare, class Cons)
import Data.Symbol (class IsSymbol, reflectSymbol, reifySymbol)
import Type.Data.Ordering (EQ)
import Prim.Symbol (class Append, class Compare, class Cons)
import Type.Data.Ordering (class Equals) as Ordering
import Type.Data.Ordering (EQ)
import Type.Proxy (Proxy(..))

compare :: forall l r o. Compare l r o => Proxy l -> Proxy r -> Proxy o
Expand All @@ -20,16 +20,17 @@ compare _ _ = Proxy
append :: forall l r o. Append l r o => Proxy l -> Proxy r -> Proxy o
append _ _ = Proxy

uncons :: forall h t s. Cons h t s => Proxy s -> {head :: Proxy h, tail :: Proxy t}
uncons _ = {head : Proxy, tail : Proxy}
uncons :: forall h t s. Cons h t s => Proxy s -> { head :: Proxy h, tail :: Proxy t }
uncons _ = { head: Proxy, tail: Proxy }

class Equals :: Symbol -> Symbol -> Boolean -> Constraint
class Equals lhs rhs out | lhs rhs -> out

instance equalsSymbol
:: (Compare lhs rhs ord,
Ordering.Equals EQ ord out)
=> Equals lhs rhs out
instance equalsSymbol ::
( Compare lhs rhs ord
, Ordering.Equals EQ ord out
) =>
Equals lhs rhs out

equals :: forall l r o. Equals l r o => Proxy l -> Proxy r -> Proxy o
equals _ _ = Proxy
12 changes: 6 additions & 6 deletions src/Type/Prelude.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ module Type.Prelude
, module Type.RowList
) where

import Type.Data.Boolean (True, False, class IsBoolean, reflectBoolean, reifyBoolean)
import Type.Data.Ordering (Ordering, LT, EQ, GT, class IsOrdering, reflectOrdering, reifyOrdering)
import Type.Proxy (Proxy(..))
import Type.Data.Symbol (class IsSymbol, reflectSymbol, reifySymbol, class Compare, compare, class Append, append)
import Type.Data.Boolean (class IsBoolean, False, True, reflectBoolean, reifyBoolean)
import Type.Data.Ordering (class IsOrdering, EQ, GT, LT, Ordering, reflectOrdering, reifyOrdering)
import Type.Data.Symbol (class Append, class Compare, class IsSymbol, append, compare, reflectSymbol, reifySymbol)
import Type.Equality (class TypeEquals, from, to)
import Type.Row (class Union, class Lacks)
import Type.RowList (class RowToList, class ListToRow)
import Type.Proxy (Proxy(..))
import Type.Row (class Lacks, class Union)
import Type.RowList (class ListToRow, class RowToList)
2 changes: 1 addition & 1 deletion src/Type/Row.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Type.Row
, type (+)
) where

import Prim.Row (class Lacks, class Nub, class Cons, class Union)
import Prim.Row (class Cons, class Lacks, class Nub, class Union)

-- | Type application for rows.
type RowApply :: forall k. (Row k -> Row k) -> Row k -> Row k
Expand Down
21 changes: 13 additions & 8 deletions src/Type/Row/Homogeneous.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ import Type.RowList (class RowToList, Cons, Nil, RowList)
-- | Ensure that every field in a row has the same type.
class Homogeneous :: forall k. Row k -> k -> Constraint
class Homogeneous row fieldType | row -> fieldType
instance homogeneous
:: ( RowToList row fields
, HomogeneousRowList fields fieldType )
=> Homogeneous row fieldType

instance homogeneous ::
( RowToList row fields
, HomogeneousRowList fields fieldType
) =>
Homogeneous row fieldType

class HomogeneousRowList :: forall k. RowList k -> k -> Constraint
class HomogeneousRowList rowList fieldType | rowList -> fieldType
instance homogeneousRowListCons
:: ( HomogeneousRowList tail fieldType
, TypeEquals fieldType fieldType2 )
=> HomogeneousRowList (Cons symbol fieldType tail) fieldType2

instance homogeneousRowListCons ::
( HomogeneousRowList tail fieldType
, TypeEquals fieldType fieldType2
) =>
HomogeneousRowList (Cons symbol fieldType tail) fieldType2

instance homogeneousRowListNil :: HomogeneousRowList Nil fieldType
Loading
Loading