mirror of
https://github.com/ilyakooo0/effects-benchmarks.git
synced 2024-10-03 19:27:34 +03:00
Upgrade to newer libraries.
This commit is contained in:
parent
63fd34c229
commit
dbc52c4e55
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
.stack-work
|
||||
.DS_Store
|
||||
core-html/
|
||||
dist
|
||||
dist-newstyle/
|
||||
|
@ -13,7 +13,7 @@ extra-source-files: README.md
|
||||
|
||||
common shared
|
||||
default-language: Haskell2010
|
||||
ghc-options: -Wall -Werror -O2
|
||||
ghc-options: -Wall -Werror -O2 -flate-specialise
|
||||
build-depends: base >= 4.7 && < 5
|
||||
|
||||
library benchmark-signatures
|
||||
@ -54,7 +54,7 @@ library instances-for-fused-effects
|
||||
exposed-modules: Fused.Stateful
|
||||
, Fused.StatefulExcept
|
||||
, Fused.HTTP
|
||||
build-depends: fused-effects >= 0.4.0.0
|
||||
build-depends: fused-effects >= 0.5
|
||||
|
||||
library instances-for-freer-simple
|
||||
import: shared
|
||||
@ -67,18 +67,15 @@ library instances-for-freer-simple
|
||||
library instances-for-polysemy
|
||||
import: shared
|
||||
hs-source-dirs: instances
|
||||
ghc-options: -fplugin=Polysemy.Plugin
|
||||
exposed-modules: Poly.Stateful
|
||||
, Poly.StatefulExcept
|
||||
, Poly.HTTP
|
||||
build-depends: polysemy ^>= 0.2.1
|
||||
, polysemy-plugin ^>= 0.2.0.0
|
||||
build-depends: polysemy ^>= 1.2
|
||||
|
||||
benchmark effects-benchmarks
|
||||
import: shared
|
||||
type: exitcode-stdio-1.0
|
||||
hs-source-dirs: src
|
||||
ghc-options: -fplugin=Polysemy.Plugin
|
||||
build-depends: benchmark-signatures
|
||||
, instances-for-mtl
|
||||
, instances-for-fused-effects
|
||||
|
@ -1,31 +1,23 @@
|
||||
{-# LANGUAGE TypeOperators, FlexibleInstances, KindSignatures, MultiParamTypeClasses, DeriveFunctor, UndecidableInstances, GeneralizedNewtypeDeriving #-}
|
||||
{-# LANGUAGE DeriveAnyClass, DeriveFunctor, DeriveGeneric, DerivingStrategies, FlexibleInstances, GeneralizedNewtypeDeriving,
|
||||
KindSignatures, MultiParamTypeClasses, TypeOperators, UndecidableInstances #-}
|
||||
|
||||
module Fused.HTTP where
|
||||
|
||||
import Control.Effect
|
||||
import Control.Effect.Sum
|
||||
import Control.Effect.Carrier
|
||||
import Data.Coerce
|
||||
import Control.Monad.IO.Class
|
||||
import GHC.Generics (Generic1)
|
||||
|
||||
newtype HttpC m a = HttpC { runHttpC :: m a }
|
||||
deriving (Applicative, Functor, Monad, MonadIO)
|
||||
deriving newtype (Applicative, Functor, Monad, MonadIO)
|
||||
|
||||
data HTTP (m :: * -> *) k
|
||||
= Open String k
|
||||
| Close k
|
||||
| Post String (String -> k)
|
||||
| HGet (String -> k)
|
||||
deriving Functor
|
||||
|
||||
instance Effect HTTP where
|
||||
handle state handler (Open s k) = Open s (handler . (<$ state) $ k)
|
||||
handle state handler (Close k) = Close (handler . (<$ state) $ k)
|
||||
handle state handler (Post s k) = Post s (handler . (<$ state) . k)
|
||||
handle state handler (HGet k) = HGet (handler . (<$ state) . k)
|
||||
|
||||
instance HFunctor HTTP where
|
||||
hmap _ = coerce
|
||||
= Open String (m k)
|
||||
| Close (m k)
|
||||
| Post String (String -> m k)
|
||||
| HGet (String -> m k)
|
||||
deriving stock (Functor, Generic1)
|
||||
deriving anyclass (HFunctor, Effect)
|
||||
|
||||
open' :: String -> HttpM ()
|
||||
open' s = send (Open s (pure ()))
|
||||
@ -46,7 +38,7 @@ instance (Effect sig, Carrier sig m) => Carrier (HTTP :+: sig) (HttpC m) where
|
||||
Open _ k -> k
|
||||
Close k -> k
|
||||
Post s k -> k ("posted " <> s)
|
||||
HGet k -> k "lmao"
|
||||
HGet k -> k "lmao"
|
||||
eff (R other) = HttpC (eff (handleCoercible other))
|
||||
|
||||
runHttp :: HttpM a -> IO a
|
||||
|
@ -1,10 +1,10 @@
|
||||
{-# LANGUAGE DataKinds, TemplateHaskell, KindSignatures, GADTs, FlexibleContexts, TypeOperators, LambdaCase #-}
|
||||
{-# LANGUAGE ScopedTypeVariables, DataKinds, TemplateHaskell, KindSignatures, GADTs, FlexibleContexts, TypeOperators, LambdaCase #-}
|
||||
|
||||
module Poly.HTTP where
|
||||
|
||||
import Polysemy
|
||||
|
||||
type HttpM = Sem '[Http, Lift IO]
|
||||
type HttpM = Sem '[Http, Final IO]
|
||||
|
||||
data Http (m :: * -> *) a where
|
||||
HOpen :: String -> Http m ()
|
||||
@ -34,4 +34,4 @@ runHttp' = interpret $ \case
|
||||
HGet -> pure "contents"
|
||||
|
||||
runHttp :: HttpM a -> IO a
|
||||
runHttp = runM . runHttp'
|
||||
runHttp = runFinal . runHttp'
|
||||
|
Loading…
Reference in New Issue
Block a user