Skip to content

Instantly share code, notes, and snippets.

@eamelink
Created October 9, 2014 06:14
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 eamelink/fd22b40c69807d4f6ce4 to your computer and use it in GitHub Desktop.
Save eamelink/fd22b40c69807d4f6ce4 to your computer and use it in GitHub Desktop.
Typeclass instance head is invalid
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
@mtiller
Copy link

mtiller commented Oct 15, 2014

I ran into a similar issue. Did you figure out what the issue was?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment