Created
October 9, 2014 06:14
-
-
Save eamelink/fd22b40c69807d4f6ce4 to your computer and use it in GitHub Desktop.
Typeclass instance head is invalid
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 Debug.Trace | |
import Control.Monad.RWS | |
import Control.Monad.RWS.Class | |
import Control.Monad.RWS.Trans | |
import Control.Monad.Identity | |
import Data.Monoid | |
import Data.Tuple | |
main = do | |
trace "Yo!" | |
trace $ showSee $ runRWS calc 42 10 | |
-- Doesn't work: | |
-- Warning: Error at src/Main.purs line 19, column 1: | |
-- Error in type (log :: w, result :: a, state :: s): | |
-- Type class instance head is invalid. Use --force to continue. | |
instance showSee :: (Show s, Show a, Show w) => Show { state :: s, result :: a, log :: w} where | |
show see = "See { " ++ | |
"state: " ++ (show see.state) ++ | |
" result: " ++ (show see.result) ++ | |
" log: " ++ (show see.log) ++ "}" | |
-- Works | |
showSee :: forall s a w. (Show s, Show a, Show w) => { state :: s, result :: a, log :: w } -> String | |
showSee see = "See { " ++ | |
"state: " ++ (show see.state) ++ | |
" result: " ++ (show see.result) ++ | |
" log: " ++ (show see.log) ++ "}" | |
calc :: RWS Number [String] Number Number | |
calc = do | |
x <- get | |
tell ["Starting with value from state:" ++ (show x)] | |
y <- ask | |
tell ["Adding the value from the read:" ++ (show y)] | |
let result = x + y | |
tell $ ["Ending up with " ++ show result] | |
put result | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I ran into a similar issue. Did you figure out what the issue was?