Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uses generic derivation for reinterpret log example #178

Merged
merged 1 commit into from
Jun 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 2 additions & 17 deletions examples/ReinterpretLog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
-- structured log messages as strings.


{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
Expand Down Expand Up @@ -107,23 +108,7 @@ runApplication =
data Log (a :: Type) (m :: Type -> Type) (k :: Type)
= Log a k
deriving stock (Functor)

-- Log is a "first order" effect, so the Effect and HFunctor instance are
-- boilerplate. See https://github.com/fused-effects/fused-effects/issues/54
instance Effect (Log a) where
handle ::
Functor f
=> f ()
-> (forall x. f (m x) -> n (f x))
-> Log a m (m b)
-> Log a n (n (f b))
handle state handler =
coerce . fmap (handler . ((<$ state)))

instance HFunctor (Log a) where
hmap :: (forall x. m x -> n x) -> Log a m k -> Log a n k
hmap _ =
coerce
deriving anyclass (HFunctor, Effect)

-- Log an 'a'.
log ::
Expand Down