polysemy/test/FusionSpec.hs

93 lines
2.5 KiB
Haskell
Raw Normal View History

{-# LANGUAGE CPP #-}
2019-03-19 06:04:21 +03:00
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -O2 #-}
{-# OPTIONS_GHC -dsuppress-idinfo -dsuppress-coercions #-}
2019-03-19 06:04:21 +03:00
#if __GLASGOW_HASKELL__ < 804
{-# OPTIONS_GHC -fplugin=Test.Inspection.Plugin #-}
#endif
2019-03-19 06:04:21 +03:00
module FusionSpec where
import qualified Control.Monad.Trans.Except as E
2019-03-19 06:28:17 +03:00
import qualified Control.Monad.Trans.State.Strict as S
2019-03-20 06:42:18 +03:00
import Polysemy.Error
2019-04-10 21:57:29 +03:00
import Polysemy.Internal
import Polysemy.Internal.Combinators
import Polysemy.Internal.Union
2019-03-20 06:42:18 +03:00
import Polysemy.State
2019-03-19 06:28:17 +03:00
import Test.Hspec
import Test.Inspection
2019-03-19 06:04:21 +03:00
isSuccess :: Result -> Bool
isSuccess (Success _) = True
isSuccess (Failure e) = error e
shouldSucceed :: Result -> Expectation
shouldSucceed r = r `shouldSatisfy` isSuccess
spec :: Spec
spec = parallel $ do
2019-03-19 06:04:21 +03:00
describe "fusion" $ do
-- #if __GLASGOW_HASKELL__ >= 807
-- it "Union proofs should simplify" $ do
-- shouldSucceed $(inspectTest $ 'countDown `hasNoType` ''SNat)
-- #endif
2019-03-19 06:04:21 +03:00
it "internal uses of StateT should simplify" $ do
shouldSucceed $(inspectTest $ 'countDown `doesNotUse` ''S.StateT)
shouldSucceed $(inspectTest $ 'jank `doesNotUse` ''S.StateT)
it "internal uses of ExceptT should simplify" $ do
shouldSucceed $(inspectTest $ 'tryIt `doesNotUse` ''E.ExceptT)
it "`runState . reinterpret` should fuse" $ do
shouldSucceed $(inspectTest $ 'jank `doesNotUse` 'reinterpret)
shouldSucceed $(inspectTest $ 'jank `doesNotUse` 'hoist)
it "who needs Sem even?" $ do
2019-04-15 20:13:16 +03:00
shouldSucceed $(inspectTest $ 'countDown `doesNotUse` 'Sem)
shouldSucceed $(inspectTest $ 'jank `doesNotUse` 'Sem)
shouldSucceed $(inspectTest $ 'tryIt `doesNotUse` 'Sem)
2019-03-19 06:04:21 +03:00
-- #if __GLASGOW_HASKELL__ >= 807
-- it "who needs Weaving even?" $ do
-- shouldSucceed $(inspectTest $ 'jank `doesNotUse` 'Weaving)
-- shouldSucceed $(inspectTest $ 'countDown `doesNotUse` 'Weaving)
-- #if __GLASGOW_HASKELL__ >= 810
-- shouldSucceed $(inspectTest $ 'tryIt `doesNotUse` 'Weaving)
-- #endif
-- #endif
2019-03-19 06:16:52 +03:00
2019-04-15 20:13:16 +03:00
go :: Sem '[State Int] Int
2019-03-19 06:04:21 +03:00
go = do
2019-04-10 21:57:29 +03:00
n <- get
2019-03-19 06:04:21 +03:00
if n <= 0
then pure n
else do
2019-04-10 21:57:29 +03:00
put (n-1)
2019-03-19 06:04:21 +03:00
go
2019-03-19 06:16:52 +03:00
2019-03-19 06:04:21 +03:00
tryIt :: Either Bool String
tryIt = run . runError @Bool $
2019-03-19 06:04:21 +03:00
catch @Bool
(throw False)
(\_ -> pure "hello")
2019-03-19 06:04:21 +03:00
2019-03-19 06:16:52 +03:00
2019-03-19 06:04:21 +03:00
countDown :: Int -> Int
countDown start = fst $ run $ runState start go
2019-03-19 06:16:52 +03:00
2019-03-19 06:04:21 +03:00
jank :: Int -> Int
2019-04-10 21:57:29 +03:00
jank start = fst $ run $ runState start $ go
2019-03-19 06:04:21 +03:00