Skip to content

Instantly share code, notes, and snippets.

@owickstrom
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owickstrom/42f5216fa107eac703c0 to your computer and use it in GitHub Desktop.
Save owickstrom/42f5216fa107eac703c0 to your computer and use it in GitHub Desktop.
Instance Effects Trouble
module Test.Spec where
import Debug.Trace
import Control.Monad
import Control.Monad.Error.Class
import Control.Monad.Trans
import Control.Monad.Eff
import Control.Monad.Eff.Exception
import Control.Monad.Eff.Class
import Control.Monad.Aff
class TestBody e body where
toAff :: body -> Aff e Unit
instance testBodyBoolean :: TestBody e Boolean where
toAff true = pure unit
toAff false = throwError $ error "Result was false"
instance testBodyAff :: TestBody e (Aff e Unit) where
toAff a = a
risky :: forall e. Aff e Unit
risky = throwError $ error "OMG NO"
test :: forall e b.
(TestBody e b) =>
b -> Aff e Unit
test body = toAff body
trueTest :: forall e. Aff e Unit
trueTest = test true
riskyTest :: forall e. Aff e Unit
riskyTest = test risky
run :: forall e. Eff (trace :: Trace | e) Unit
run = do
runAff print print trueTest
runAff print print riskyTest
Compiling Test.Spec
Error in module Test.Spec:
Error in value declaration riskyTest:
Error at src/Test/Spec.purs line 3, column 1 - line 4, column 1:
No instance found for Test.Spec.TestBody e57 (Control.Monad.Aff.Aff u60 Prelude.Unit)
See https://github.com/purescript/purescript/wiki/Error-Code-NoInstanceFound for more information, or to contribute content related to this error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment