Skip to content

Commit c393ee5

Browse files
matthewleonpaf31
authored andcommitted
trivial Lazy instance for functions (#38)
* trivial Lazy instance for functions * make lazyFn defer actually defer fn call Add tests for this. * relax types in tests
1 parent 33bcce0 commit c393ee5

File tree

6 files changed

+40
-3
lines changed

6 files changed

+40
-3
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ install:
1111
- chmod a+x $HOME/purescript
1212
- npm install -g bower
1313
- npm install
14-
- bower install
1514
script:
15+
- bower install --production
1616
- npm run -s build
17+
- bower install
18+
- npm -s test
1719
after_success:
1820
- >-
1921
test $TRAVIS_TAG &&

bower.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
],
1919
"dependencies": {
2020
"purescript-prelude": "^3.0.0"
21+
},
22+
"devDependencies": {
23+
"purescript-eff": "^3.1.0"
2124
}
2225
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"private": true,
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
5-
"build": "pulp build -- --censor-lib --strict"
5+
"build": "pulp build -- --censor-lib --strict",
6+
"test": "pulp test"
67
},
78
"devDependencies": {
89
"pulp": "^10.0.4",

src/Control/Lazy.purs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Control.Lazy where
22

3-
import Data.Unit (Unit)
3+
import Data.Unit (Unit, unit)
44

55
-- | The `Lazy` class represents types which allow evaluation of values
66
-- | to be _deferred_.
@@ -10,6 +10,9 @@ import Data.Unit (Unit)
1010
class Lazy l where
1111
defer :: (Unit -> l) -> l
1212

13+
instance lazyFn :: Lazy (a -> b) where
14+
defer f = \x -> f unit x
15+
1316
-- | `fix` defines a value as the fixed point of a function.
1417
-- |
1518
-- | The `Lazy` instance allows us to generate the result lazily.

test/Test/Control/Lazy.purs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module Test.Control.Lazy (testLazy) where
2+
3+
import Control.Applicative (pure)
4+
import Control.Monad.Eff (Eff)
5+
import Control.Lazy (fix)
6+
import Data.Unit (Unit, unit)
7+
8+
foo :: forall a. a -> Unit
9+
foo _ = unit
10+
11+
foofoo :: forall a b. a -> (b -> Unit)
12+
foofoo _ = foo
13+
14+
foo' :: forall a. a -> Unit
15+
foo' = fix foofoo
16+
17+
-- the idea here is that foo and foo' are the same function
18+
testLazy :: Eff () Unit
19+
testLazy = pure (foo' unit)

test/Test/Main.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Test.Main (main) where
2+
3+
import Control.Monad.Eff (Eff)
4+
import Data.Unit (Unit)
5+
6+
import Test.Control.Lazy (testLazy)
7+
8+
main :: Eff () Unit
9+
main = testLazy

0 commit comments

Comments
 (0)