purescript/purescript-transformers

Possible bug in RWST

joneshf opened this issue · 0 comments

I might be doing something stupid here, but the equivalent haskell code has the correct output.

module Foo where

import Control.Monad.RWS
import Control.Monad.RWS.Trans

import Data.Traversable
import Data.Tuple

import Debug.Trace

data Foo = Foo String | Bar [Foo]

type FooEnv = RWST Foo String Number

eval :: forall m. (Applicative m, Monad m) => FooEnv m [String]
eval = ask >>= \f -> case f of
    Bar foos -> do
        idents <- for foos $ \foo -> local (const foo) eval
        -- do something with idents
        return []
    Foo str -> do
        num <- get
        modify (+1)
        let ident = "foo" ++ show num ++ " "
        tell $ ident ++ " " ++ str
        tell "\n"
        return [ident]

foo :: Foo
foo = Bar [Foo "wat", Foo "yep", Foo "nope", Bar [Foo "oh", Foo "sure"]]

main = evalRWST eval foo 0 >>= trace <<< snd

output:

foo0  wat
foo0  yep
foo0  nope
foo0  oh
foo0  sure

expected:

foo0  wat
foo1  yep
foo2  nope
foo3  oh
foo4  sure