-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* global exports, require */ | ||
"use strict"; | ||
|
||
// module Control.Monad.Fix | ||
|
||
var message = "Control.Monad.Fix: Premature access to result of fixpoint computation." | ||
|
||
function f(x) { | ||
console.log(x) | ||
return 1 | ||
} | ||
|
||
var myobj = { a: f(myobj), b: 2 } | ||
|
||
// fixEffect :: forall eff a. ((Unit -> a) -> Eff eff a) -> Eff eff a | ||
exports.fixEffect = function(f) { | ||
return function() { | ||
var result = null; | ||
var ready = false; | ||
|
||
result = f(function(u) { | ||
if (!ready) throw new Error(message); | ||
return result; | ||
})(); | ||
|
||
ready = true; | ||
return result; | ||
} | ||
} | ||
|
||
// fixPure :: forall a. ((Unit -> a) -> a) -> a | ||
exports.fixPure = function(f) { | ||
return exports.fixEffect(function(a) { return function () { return f(a); }})(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters