[<<][meta][>>][..]

Wed Feb 10 09:17:53 CET 2010

## Expected kind `* -> *', but `Code a' has kind `*'

Some grave conceptual error in the following code?
instance Monad (Code a)
where return = returnCode
(>>=) = bindCode
include p ps = if' (p `elem` ps) ps (p:ps)
join xs ys = foldr include ys xs
common op' [] = op'
common op' (op:ops) = if' (op' == op) op (common op' ops)
returnCode r = Code r (case r of
Node n -> Env [] [n]
Var v -> Env [v] []
Lit l -> Env [] [])
bindCode (Code t (Env vs ps)) combine =
case combine t of
Code t' (Env vs' ps') ->
let ps'' = join ps ps'
vs'' = join vs vs'
e'' = Env vs'' ps''
in
case t' of
Node p' -> Code (Node (common p' ps'')) e''
_ -> Code t' e''
Hmm.. Obscure message[1]. The correct line seems to be:
instance Monad Code
where return = returnCode
(>>=) = bindCode
I.e. Monad expects a type constructor, not a type.
Ok, I see.. The problem is that an environment is a container for
Term types, not the number type Terms are parameterized over.
Solution: an environment is an addition to terms that tracks sharing
between nodes. Terms themselves are syntax trees and are
self-contained, except for external variable inputs which are treated
as constants anyway.
[1] http://hackage.haskell.org/trac/ghc/ticket/1633

[Reply][About]

[<<][meta][>>][..]