Skip to content

Commit 6e14a53

Browse files
committed
Merge branch 'master' into addDocs
2 parents 85039e8 + 268870d commit 6e14a53

File tree

9 files changed

+75
-11
lines changed

9 files changed

+75
-11
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ node_js: stable
55
env:
66
- PATH=$HOME/purescript:$PATH
77
install:
8-
- TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest))
8+
- TAG=v0.14.0-rc2
9+
# - TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest))
910
- curl --location --output $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
1011
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
1112
- chmod a+x $HOME/purescript

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
55
"build": "eslint src && pulp build -- --censor-lib --strict",
6-
"test": "pulp test --no-check-main"
6+
"test": "pulp test"
77
},
88
"devDependencies": {
99
"eslint": "^4.19.1",
1010
"purescript-psa": "^0.6.0",
11-
"pulp": "^12.2.0",
11+
"pulp": "^15.0.0",
1212
"rimraf": "^2.6.2"
1313
}
1414
}

src/Control/Apply.purs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ infixl 4 applySecond as *>
6868

6969
-- | Lift a function of two arguments to a function which accepts and returns
7070
-- | values wrapped with the type constructor `f`.
71+
-- |
72+
-- | ```purescript
73+
-- | lift2 add (Just 1) (Just 2) == Just 3
74+
-- | lift2 add Nothing (Just 2) == Nothing
75+
-- |```
76+
-- |
7177
lift2 :: forall a b c f. Apply f => (a -> b -> c) -> f a -> f b -> f c
7278
lift2 f a b = f <$> a <*> b
7379

src/Data/Bounded.purs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@ module Data.Bounded
33
, bottom
44
, top
55
, module Data.Ord
6+
, class BoundedRecord, bottomRecord, topRecord
67
) where
78

8-
import Data.Ord (class Ord, Ordering(..), compare, (<), (<=), (>), (>=))
9+
import Data.Ord (class Ord, class OrdRecord, Ordering(..), compare, (<), (<=), (>), (>=))
10+
import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol)
911
import Data.Unit (Unit, unit)
12+
import Prim.Row as Row
13+
import Prim.RowList as RL
14+
import Record.Unsafe (unsafeSet)
15+
import Type.Data.Row (RProxy(..))
16+
import Type.Data.RowList (RLProxy(..))
1017

1118
-- | The `Bounded` type class represents totally ordered types that have an
1219
-- | upper and lower boundary.
@@ -54,3 +61,41 @@ foreign import bottomNumber :: Number
5461
instance boundedNumber :: Bounded Number where
5562
top = topNumber
5663
bottom = bottomNumber
64+
65+
class OrdRecord rowlist row <= BoundedRecord rowlist row subrow | rowlist -> subrow where
66+
topRecord :: RLProxy rowlist -> RProxy row -> Record subrow
67+
bottomRecord :: RLProxy rowlist -> RProxy row -> Record subrow
68+
69+
instance boundedRecordNil :: BoundedRecord RL.Nil row () where
70+
topRecord _ _ = {}
71+
bottomRecord _ _ = {}
72+
73+
instance boundedRecordCons
74+
:: ( IsSymbol key
75+
, Bounded focus
76+
, Row.Cons key focus rowTail row
77+
, Row.Cons key focus subrowTail subrow
78+
, BoundedRecord rowlistTail row subrowTail
79+
)
80+
=> BoundedRecord (RL.Cons key focus rowlistTail) row subrow where
81+
topRecord _ rowProxy
82+
= insert top tail
83+
where
84+
key = reflectSymbol (SProxy :: SProxy key)
85+
insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow
86+
tail = topRecord (RLProxy :: RLProxy rowlistTail) rowProxy
87+
88+
bottomRecord _ rowProxy
89+
= insert bottom tail
90+
where
91+
key = reflectSymbol (SProxy :: SProxy key)
92+
insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow
93+
tail = bottomRecord (RLProxy :: RLProxy rowlistTail) rowProxy
94+
95+
instance boundedRecord
96+
:: ( RL.RowToList row list
97+
, BoundedRecord list row row
98+
)
99+
=> Bounded (Record row) where
100+
top = topRecord (RLProxy :: RLProxy list) (RProxy :: RProxy row)
101+
bottom = bottomRecord (RLProxy :: RLProxy list) (RProxy :: RProxy row)

src/Data/Function.purs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ flip f b a = f a b
2626
-- | ```purescript
2727
-- | const 1 "hello" = 1
2828
-- | ```
29+
-- |
30+
-- | It can also be thought of as creating a function that ignores its argument:
31+
-- |
32+
-- | ```purescript
33+
-- | const 1 = \_ -> 1
34+
-- | ```
2935
const :: forall a b. a -> b -> a
3036
const a _ = a
3137

@@ -56,7 +62,7 @@ apply f x = f x
5662
infixr 0 apply as $
5763

5864
-- | Applies an argument to a function. This is primarily used as the `(#)`
59-
-- | operator, which allows parentheses to be ommitted in some cases, or as a
65+
-- | operator, which allows parentheses to be omitted in some cases, or as a
6066
-- | natural way to apply a value to a chain of composed functions.
6167
applyFlipped :: forall a b. a -> (a -> b) -> b
6268
applyFlipped x f = f x

src/Data/Unit.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import Data.Show (class Show)
77
-- |
88
-- | `Unit` is often used, wrapped in a monadic type constructor, as the
99
-- | return type of a computation where only the _effects_ are important.
10+
-- |
11+
-- | When returning a value of type `Unit` from an FFI function, it is
12+
-- | recommended to use `undefined`, or not return a value at all.
1013
foreign import data Unit :: Type
1114

1215
-- | `unit` is the sole inhabitant of the `Unit` type.

src/Type/Data/Row.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ module Type.Data.Row where
1616
-- | { x :: Int, y :: Int } -> { x :: Int, y :: Int }
1717
-- | ```
1818
-- | Here `row` has been specialised to `( x :: Int, y :: Int )`.
19-
data RProxy (row :: # Type)
19+
data RProxy (row :: Row Type)
2020
= RProxy

src/Type/Data/RowList.purs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module Type.Data.RowList where
22

33
import Prim.RowList (kind RowList)
44

5-
-- | A proxy data type whose type parameter is a type of kind `RowList`.
6-
-- |
7-
-- | Commonly used for specialising a function with a quantified type.
8-
data RLProxy (rowlist :: RowList)
5+
-- | A proxy to carry information about a rowlist.
6+
data RLProxy (rowlist :: RowList Type)
97
= RLProxy

test/Test/Main.purs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,9 @@ testRecordInstances = do
149149
testOrd { a: 42, b: "hello" } { a: 42, b: "hello" } EQ
150150
testOrd { a: 42, b: "hell" } { a: 42, b: "hello" } LT
151151
testOrd { a: 42, b: "hello" } { a: 42, b: "hell" } GT
152-
152+
assert "Record bottom" $
153+
(bottom :: { a :: Boolean }).a
154+
== bottom
155+
assert "Record top" $
156+
(top :: { a :: Boolean }).a
157+
== top

0 commit comments

Comments
 (0)