git.iko.soy/effects-benchmarks
on master help sign in
Upgrade to newer libraries.
commitdbc52c4e5510530437a1cc2f3cb3b44d3c788aa9 authorPatrick Thomson <patrickt@github.com> dateWed 4 Sep 2019, 17:00 (7 years ago) parent63fd34c
4 files changed+18−28
.gitignore+1 effects-benchmarks.cabal+3−6 instances/Fused/HTTP.hs+11−19 instances/Poly/HTTP.hs+3−3
.gitignore+1
@@ -1,4 +1,5 @@
11.stack-work
22.DS_Store
33core-html/
4+dist
45dist-newstyle/
effects-benchmarks.cabal+3−6
@@ -13,7 +13,7 @@ extra-source-files: README.md
1313
1414common shared
1515 default-language: Haskell2010
16− ghc-options: -Wall -Werror -O2
16+ ghc-options: -Wall -Werror -O2 -flate-specialise
1717 build-depends: base >= 4.7 && < 5
1818
1919library benchmark-signatures
@@ -54,7 +54,7 @@ library instances-for-fused-effects
5454 exposed-modules: Fused.Stateful
5555 , Fused.StatefulExcept
5656 , Fused.HTTP
57− build-depends: fused-effects >= 0.4.0.0
57+ build-depends: fused-effects >= 0.5
5858
5959library instances-for-freer-simple
6060 import: shared
@@ -67,18 +67,15 @@ library instances-for-freer-simple
6767library instances-for-polysemy
6868 import: shared
6969 hs-source-dirs: instances
70− ghc-options: -fplugin=Polysemy.Plugin
7170 exposed-modules: Poly.Stateful
7271 , Poly.StatefulExcept
7372 , Poly.HTTP
74− build-depends: polysemy ^>= 0.2.1
75− , polysemy-plugin ^>= 0.2.0.0
73+ build-depends: polysemy ^>= 1.2
7674
7775benchmark effects-benchmarks
7876 import: shared
7977 type: exitcode-stdio-1.0
8078 hs-source-dirs: src
81− ghc-options: -fplugin=Polysemy.Plugin
8279 build-depends: benchmark-signatures
8380 , instances-for-mtl
8481 , instances-for-fused-effects
instances/Fused/HTTP.hs+11−19
@@ -1,31 +1,23 @@
1−{-# LANGUAGE TypeOperators, FlexibleInstances, KindSignatures, MultiParamTypeClasses, DeriveFunctor, UndecidableInstances, GeneralizedNewtypeDeriving #-}
1+{-# LANGUAGE DeriveAnyClass, DeriveFunctor, DeriveGeneric, DerivingStrategies, FlexibleInstances, GeneralizedNewtypeDeriving,
2+ KindSignatures, MultiParamTypeClasses, TypeOperators, UndecidableInstances #-}
23
34module Fused.HTTP where
45
56import Control.Effect
6−import Control.Effect.Sum
77import Control.Effect.Carrier
8−import Data.Coerce
98import Control.Monad.IO.Class
9+import GHC.Generics (Generic1)
1010
1111newtype HttpC m a = HttpC { runHttpC :: m a }
12− deriving (Applicative, Functor, Monad, MonadIO)
12+ deriving newtype (Applicative, Functor, Monad, MonadIO)
1313
1414data HTTP (m :: * -> *) k
15− = Open String k
16− | Close k
17− | Post String (String -> k)
18− | HGet (String -> k)
19− deriving Functor
20−
21−instance Effect HTTP where
22− handle state handler (Open s k) = Open s (handler . (<$ state) $ k)
23− handle state handler (Close k) = Close (handler . (<$ state) $ k)
24− handle state handler (Post s k) = Post s (handler . (<$ state) . k)
25− handle state handler (HGet k) = HGet (handler . (<$ state) . k)
26−
27−instance HFunctor HTTP where
28− hmap _ = coerce
15+ = Open String (m k)
16+ | Close (m k)
17+ | Post String (String -> m k)
18+ | HGet (String -> m k)
19+ deriving stock (Functor, Generic1)
20+ deriving anyclass (HFunctor, Effect)
2921
3022open' :: String -> HttpM ()
3123open' s = send (Open s (pure ()))
@@ -46,7 +38,7 @@ instance (Effect sig, Carrier sig m) => Carrier (HTTP :+: sig) (HttpC m) where
4638 Open _ k -> k
4739 Close k -> k
4840 Post s k -> k ("posted " <> s)
49− HGet k -> k "lmao"
41+ HGet k -> k "lmao"
5042 eff (R other) = HttpC (eff (handleCoercible other))
5143
5244runHttp :: HttpM a -> IO a
instances/Poly/HTTP.hs+3−3
@@ -1,10 +1,10 @@
1−{-# LANGUAGE DataKinds, TemplateHaskell, KindSignatures, GADTs, FlexibleContexts, TypeOperators, LambdaCase #-}
1+{-# LANGUAGE ScopedTypeVariables, DataKinds, TemplateHaskell, KindSignatures, GADTs, FlexibleContexts, TypeOperators, LambdaCase #-}
22
33module Poly.HTTP where
44
55import Polysemy
66
7−type HttpM = Sem '[Http, Lift IO]
7+type HttpM = Sem '[Http, Final IO]
88
99data Http (m :: * -> *) a where
1010 HOpen :: String -> Http m ()
@@ -34,4 +34,4 @@ runHttp' = interpret $ \case
3434 HGet -> pure "contents"
3535
3636runHttp :: HttpM a -> IO a
37−runHttp = runM . runHttp'
37+runHttp = runFinal . runHttp'