File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424 " package.json"
2525 ],
2626 "dependencies" : {
27- "purescript-identity" : " ~ 0.4.0" ,
28- "purescript-eff" : " ~ 0.1.0" ,
29- "purescript-either" : " ~ 0.2.0" ,
30- "purescript-st" : " ~ 0.1.0"
27+ "purescript-identity" : " ^ 0.4.0" ,
28+ "purescript-eff" : " ^ 0.1.0" ,
29+ "purescript-either" : " ^ 0.2.0" ,
30+ "purescript-st" : " ^ 0.1.0"
3131 },
3232 "devDependencies" : {
33- "purescript-console" : " ~ 0.1.0"
33+ "purescript-console" : " ^ 0.1.0"
3434 }
3535}
Original file line number Diff line number Diff line change @@ -7,12 +7,6 @@ class (Monad m) <= MonadRec m where
77 tailRecM :: forall a b. (a -> m (Either a b)) -> a -> m b
88```
99
10- ##### Instances
11- ``` purescript
12- instance monadRecIdentity :: MonadRec Identity
13- instance monadRecEff :: MonadRec (Eff eff)
14- ```
15-
1610This type class captures those monads which support tail recursion in constant stack space.
1711
1812The ` tailRecM ` function takes a step function, and applies that step function recursively
@@ -34,6 +28,12 @@ loopWriter n = tailRecM go n
3428 return (Left (n - 1))
3529```
3630
31+ ##### Instances
32+ ``` purescript
33+ instance monadRecIdentity :: MonadRec Identity
34+ instance monadRecEff :: MonadRec (Eff eff)
35+ ```
36+
3737#### ` tailRecM2 `
3838
3939``` purescript
Original file line number Diff line number Diff line change 33 "devDependencies" : {
44 "gulp" : " ^3.8.11" ,
55 "gulp-plumber" : " ^1.0.0" ,
6- "gulp-purescript" : " ^0.5.0" ,
7- "gulp-run" : " ~ 1.6.7" ,
6+ "gulp-purescript" : " ^0.5.0-rc.1 " ,
7+ "gulp-run" : " ^ 1.6.7" ,
88 "rimraf" : " ^2.3.3"
99 }
1010}
Original file line number Diff line number Diff line change 11module Test.Main where
22
33import Prelude
4-
5- import Console
64import Control.Monad (when )
7- import Control.Monad.Eff
5+ import Control.Monad.Eff (Eff ())
6+ import Control.Monad.Eff.Console (CONSOLE (), log , print )
87import Control.Monad.Rec.Class
9- import Data.Either
10- import Data.Identity
11- import Data.Maybe
12- -- import Data.Monoid
13- -- import Data.Monoid.Additive
8+ import Data.Either (Either (..))
149
1510-- | Compute the nth triangle number
1611triangle :: Int -> Eff (console :: CONSOLE ) Int
@@ -41,6 +36,7 @@ mutual = tailRec go <<< Left
4136 odd 0 = Right false
4237 odd n = Left (Left (n - 1 ))
4338
39+ main :: Eff (console :: CONSOLE ) Unit
4440main = do
4541 triangle 10
4642 print $ mutual 1000001
You can’t perform that action at this time.
0 commit comments