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 1 commit
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
Prev Previous commit
Next Next commit
make lazyFn defer actually defer fn call
Add tests for this.
  • Loading branch information
matthewleon committed Apr 4, 2017
commit 2ad5e710a565d8fd72c7b21ee2dc9ce5702787b5
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
2 changes: 1 addition & 1 deletion src/Control/Lazy.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Lazy l where
defer :: (Unit -> l) -> l

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I see it, this definitely looks like the right thing 👍


-- | `fix` defines a value as the fixed point of a function.
-- |
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 :: Unit -> Unit
foo _ = unit

foofoo :: (Unit -> Unit) -> (Unit -> Unit)
foofoo _ = foo

foo' :: Unit -> 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