2019-06-18 19:36:38 +03:00
|
|
|
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
|
|
|
|
|
|
|
|
module TypeErrors where
|
|
|
|
|
|
|
|
-- $setup
|
|
|
|
-- >>> default ()
|
|
|
|
-- >>> :m +Polysemy
|
|
|
|
-- >>> :m +Polysemy.Output
|
|
|
|
-- >>> :m +Polysemy.Reader
|
|
|
|
-- >>> :m +Polysemy.Resource
|
|
|
|
-- >>> :m +Polysemy.State
|
|
|
|
-- >>> :m +Polysemy.Trace
|
2019-06-30 06:37:56 +03:00
|
|
|
-- >>> :m +Data.Maybe
|
2019-06-18 19:36:38 +03:00
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- |
|
|
|
|
-- >>> :{
|
|
|
|
-- foo :: Sem r ()
|
|
|
|
-- foo = put ()
|
|
|
|
-- :}
|
|
|
|
-- ...
|
|
|
|
-- ... Ambiguous use of effect 'State'
|
|
|
|
-- ...
|
|
|
|
-- ... (Member (State ()) r) ...
|
|
|
|
-- ...
|
|
|
|
ambiguousMonoState = ()
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- |
|
|
|
|
-- >>> :{
|
|
|
|
-- foo :: Sem r ()
|
|
|
|
-- foo = put 5
|
|
|
|
-- :}
|
|
|
|
-- ...
|
|
|
|
-- ... Ambiguous use of effect 'State'
|
|
|
|
-- ...
|
|
|
|
-- ... (Member (State s0) r) ...
|
|
|
|
-- ...
|
|
|
|
-- ... 's0' directly...
|
|
|
|
-- ...
|
|
|
|
ambiguousPolyState = ()
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- |
|
|
|
|
-- >>> :{
|
2019-07-03 23:05:51 +03:00
|
|
|
-- interpret @(Reader Bool) $ \case
|
2019-06-18 19:36:38 +03:00
|
|
|
-- Ask -> undefined
|
|
|
|
-- :}
|
|
|
|
-- ...
|
2019-07-03 23:05:51 +03:00
|
|
|
-- ... 'Reader Bool' is higher-order, but 'interpret' can help only
|
2019-06-18 19:36:38 +03:00
|
|
|
-- ... with first-order effects.
|
|
|
|
-- ...
|
|
|
|
-- ... 'interpretH' instead.
|
|
|
|
-- ...
|
|
|
|
interpretBadFirstOrder = ()
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- |
|
|
|
|
-- >>> :{
|
|
|
|
-- runFoldMapOutput
|
|
|
|
-- :: forall o m r a
|
|
|
|
-- . Monoid m
|
|
|
|
-- => (o -> m)
|
|
|
|
-- -> Sem (Output o ': r) a
|
|
|
|
-- -> Sem r (m, a)
|
|
|
|
-- runFoldMapOutput f = runState mempty . reinterpret $ \case
|
2019-06-20 00:25:37 +03:00
|
|
|
-- Output o -> modify (`mappend` f o)
|
2019-06-18 19:36:38 +03:00
|
|
|
-- :}
|
|
|
|
-- ...
|
|
|
|
-- ... Probable cause: ...reinterpret... is applied to too few arguments
|
|
|
|
-- ...
|
|
|
|
tooFewArgumentsReinterpret = ()
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- |
|
|
|
|
-- >>> :{
|
|
|
|
-- let reinterpretScrub :: Sem (Output Int ': m) a -> Sem (State Bool ': Trace ': m) a
|
|
|
|
-- reinterpretScrub = undefined
|
|
|
|
-- foo :: Sem '[Output Int] ()
|
|
|
|
-- foo = pure ()
|
|
|
|
-- foo' = reinterpretScrub foo
|
|
|
|
-- foo'' = runState True foo'
|
|
|
|
-- foo''' = runTraceIO foo''
|
|
|
|
-- in runM foo'''
|
|
|
|
-- :}
|
|
|
|
-- ...
|
2019-06-30 06:37:56 +03:00
|
|
|
-- ... Unhandled effect 'Lift IO'
|
2019-06-18 19:36:38 +03:00
|
|
|
-- ...
|
2019-06-30 06:37:56 +03:00
|
|
|
-- ... Expected type: Sem '[Lift m] (Bool, ())
|
|
|
|
-- ... Actual type: Sem '[] (Bool, ())
|
2019-06-18 19:36:38 +03:00
|
|
|
-- ...
|
2019-06-30 06:37:56 +03:00
|
|
|
runningTooManyEffects = ()
|
2019-06-18 19:36:38 +03:00
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- |
|
|
|
|
-- >>> :{
|
|
|
|
-- foo :: Sem (State Int ': r) ()
|
|
|
|
-- foo = put ()
|
|
|
|
-- :}
|
|
|
|
-- ...
|
|
|
|
-- ... Ambiguous use of effect 'State'
|
|
|
|
-- ...
|
2019-07-04 14:45:09 +03:00
|
|
|
-- ... (Member (State ()) (State Int : r)) ...
|
2019-06-18 19:36:38 +03:00
|
|
|
-- ...
|
2019-07-04 14:45:09 +03:00
|
|
|
ambiguousSendInConcreteR = ()
|
2019-06-18 19:36:38 +03:00
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- |
|
|
|
|
-- >>> :{
|
|
|
|
-- let foo :: Member Resource r => Sem r ()
|
|
|
|
-- foo = undefined
|
|
|
|
-- in runM $ runResourceInIO foo
|
|
|
|
-- :}
|
|
|
|
-- ...
|
2019-06-30 06:37:56 +03:00
|
|
|
-- ... Couldn't match expected type ...
|
|
|
|
-- ... with actual type ...
|
|
|
|
-- ... Probable cause: ... is applied to too few arguments
|
2019-06-18 19:36:38 +03:00
|
|
|
-- ...
|
2019-06-30 06:37:56 +03:00
|
|
|
missingArgumentToRunResourceInIO = ()
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- |
|
|
|
|
-- >>> :{
|
|
|
|
-- existsKV :: Member (State (Maybe Int)) r => Sem r Bool
|
|
|
|
-- existsKV = isJust get
|
|
|
|
-- :}
|
2019-06-18 19:36:38 +03:00
|
|
|
-- ...
|
2019-06-30 06:37:56 +03:00
|
|
|
-- ... Ambiguous use of effect 'State'
|
2019-06-18 19:36:38 +03:00
|
|
|
-- ...
|
|
|
|
--
|
2019-07-04 16:35:33 +03:00
|
|
|
-- NOTE: This is fixed by enabling the plugin!
|
|
|
|
missingFmap'PLUGIN = ()
|
2019-06-18 19:36:38 +03:00
|
|
|
|
2019-07-04 14:45:09 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- |
|
|
|
|
-- >>> :{
|
|
|
|
-- foo :: Sem '[State Int, Lift IO] ()
|
|
|
|
-- foo = output ()
|
|
|
|
-- :}
|
|
|
|
-- ...
|
|
|
|
-- ... Unhandled effect 'Output ()'
|
|
|
|
-- ...
|
|
|
|
-- ... add an interpretation for 'Output ()'
|
|
|
|
-- ...
|
|
|
|
missingEffectInStack'WRONG = ()
|
|
|
|
|