Last active
December 8, 2016 20:07
-
-
Save owickstrom/a8ce95a12d513cba2f7022311bebebeb to your computer and use it in GitHub Desktop.
PureScript record and mutual recursion problem with Instances
This file contains hidden or 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
Mutual recursive definitions within records, when using type class constraints, fail to compile. |
This file contains hidden or 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
Error found: | |
in module Main | |
at /home/owi/projects/mutual-recursion-typeclass/src/Main.purs line 14, column 1 - line 14, column 37 | |
No type class instance was found for | |
Control.Monad.Monad m0 | |
while checking that expression { f: \n -> | |
(...) n | |
} | |
has type forall m. | |
{ f :: Int -> m Int | |
} | |
while checking type of property accessor (makeDecr bar).f | |
while applying a function makeDecr | |
of type forall m. | |
(Monad m) => { f :: Int -> m Int | |
} | |
-> { f :: Int -> m Int | |
} | |
to argument bar | |
in binding group foo, bar | |
where m0 is a rigid type variable | |
bound at line 14, column 1 - line 14, column 37 | |
See https://github.com/purescript/purescript/wiki/Error-Code-NoInstanceFound for more information, | |
or to contribute content related to this error. | |
Compiling Main | |
* ERROR: Subcommand terminated with exit code 1 |
This file contains hidden or 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
module Main where | |
import Prelude | |
import Control.Monad.Eff (Eff) | |
import Control.Monad.Eff.Console (CONSOLE, log) | |
type R m = { f ∷ Int → m Int } | |
makeDecr ∷ ∀ m. Monad m ⇒ R m → R m | |
makeDecr r = { f: \n → if n > 0 then r.f (n - 1) else pure n } | |
-- `foo :: ∀ e. R (Eff e)` would compile | |
foo :: ∀ m. R m | |
foo = { f: \n → (makeDecr bar).f n } | |
-- `bar :: ∀ e. R (Eff e)` would compile | |
bar :: ∀ m. R m | |
bar = { f: \n → (makeDecr foo).f n } | |
main :: forall e. Eff ( console :: CONSOLE | e ) Unit | |
main = show <$> foo.f 10 >>= log | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment