dorchard / effect-monad

Provides 'graded monads' and 'parameterised monads' to Haskell, enabling fine-grained reasoning about effects.
BSD 2-Clause "Simplified" License
99 stars 11 forks source link

State updates (get-then-put) do not compose #6

Open sheyll opened 8 years ago

sheyll commented 8 years ago

Why does the compiler not accept inc2 in the example below?


{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeSynonymInstances #-}
module EffectsInHaskellProblem where

import           Control.Effect
import           Control.Effect.State
import           GHC.TypeLits
import           Prelude               hiding (log, Monad(..), (>>))

varX :: Var "x"
varX = Var

inc :: State '["x" :-> Int :! 'RW] ()
inc =
    get varX >>= (put varX . (+1))

-- No instance for (Control.Effect.State.Nubable '["x" :-> (Int :! 'W)] '[])
inc2 =
    inc >>=
    \_ ->
         inc
jimcrayne commented 8 years ago

The build doesn't work for me unless I use type-level-sets == 0.5. However, I don't see this problem at all, inc2 works fine for me. (on ghc 7.8.3).