Skip to content

trivial Lazy instance for functions #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 28, 2017
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
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ install:
- chmod a+x $HOME/purescript
- npm install -g bower
- npm install
- bower install
script:
- bower install --production
- npm run -s build
- bower install
- npm -s test
after_success:
- >-
test $TRAVIS_TAG &&
Expand Down
3 changes: 3 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
],
"dependencies": {
"purescript-prelude": "^3.0.0"
},
"devDependencies": {
"purescript-eff": "^3.1.0"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"private": true,
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "pulp build -- --censor-lib --strict"
"build": "pulp build -- --censor-lib --strict",
"test": "pulp test"
},
"devDependencies": {
"pulp": "^10.0.4",
Expand Down
5 changes: 4 additions & 1 deletion src/Control/Lazy.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Control.Lazy where

import Data.Unit (Unit)
import Data.Unit (Unit, unit)

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

instance lazyFn :: Lazy (a -> b) where
defer f = \x -> f unit x

-- | `fix` defines a value as the fixed point of a function.
-- |
-- | The `Lazy` instance allows us to generate the result lazily.
Expand Down
19 changes: 19 additions & 0 deletions test/Test/Control/Lazy.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Test.Control.Lazy (testLazy) where

import Control.Applicative (pure)
import Control.Monad.Eff (Eff)
import Control.Lazy (fix)
import Data.Unit (Unit, unit)

foo :: forall a. a -> Unit
foo _ = unit

foofoo :: forall a b. a -> (b -> Unit)
foofoo _ = foo

foo' :: forall a. a -> Unit
foo' = fix foofoo

-- the idea here is that foo and foo' are the same function
testLazy :: Eff () Unit
testLazy = pure (foo' unit)
9 changes: 9 additions & 0 deletions test/Test/Main.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Test.Main (main) where

import Control.Monad.Eff (Eff)
import Data.Unit (Unit)

import Test.Control.Lazy (testLazy)

main :: Eff () Unit
main = testLazy