Skip to content

Commit

Permalink
Switch from Polysemy to effectful
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrosso committed Jul 22, 2022
1 parent 1dc3c0b commit c2cabd3
Show file tree
Hide file tree
Showing 50 changed files with 596 additions and 639 deletions.
4 changes: 3 additions & 1 deletion .hindent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extensions:
- FlexibleContexts
- FlexibleInstances
- FunctionalDependencies
- GADTs
- GeneralizedNewtypeDeriving
- InstanceSigs
- KindSignatures
Expand All @@ -20,9 +21,10 @@ extensions:
- MultiWayIf
- NoImplicitPrelude
- OverloadedStrings
- PolyKinds
- RankNTypes
- ScopedTypeVariables
- StandaloneDeriving
- TupleSections
- TypeApplications
- TypeFamilies
- TypeOperators
4 changes: 3 additions & 1 deletion .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- -XFlexibleContexts
- -XFlexibleInstances
- -XFunctionalDependencies
- -XGADTs
- -XGeneralizedNewtypeDeriving
- -XInstanceSigs
- -XKindSignatures
Expand All @@ -31,11 +32,12 @@
- -XMultiWayIf
- -XNoImplicitPrelude
- -XOverloadedStrings
- -XPolyKinds
- -XRankNTypes
- -XScopedTypeVariables
- -XStandaloneDeriving
- -XTupleSections
- -XTypeApplications
- -XTypeFamilies
- -XTypeOperators

- modules:
Expand Down
8 changes: 4 additions & 4 deletions app/Main.axel
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
commandParserInfo])
(import Control.Monad [void])
(importq Data.Map Map [empty])
(importq Effectful Eff all)
(importq Effectful.State.Static.Local Eff all)
(import Options.Applicative [execParser])
(importq Polysemy Sem all)
(importq Polysemy.State Sem all)

(raw "import Prelude hiding (putStrLn)")

(def app ([] {Command -> (Sem.Sem AppEffs Unit)})
(def app ([] {Command -> (Eff.Eff AppEffs Unit)})
([(FileCommand fileCommand)]
(case fileCommand
((ConvertFile filePath) (void (convertFileInPlace filePath)))
((FormatFile filePath) (formatFileInPlace filePath))
((RunFile filePath)
(void
(Sem.evalState Map.empty
(Eff.evalState Map.empty
(withGhci (transpileFileInPlace filePath)))))))
([(ProjectCommand projectCommand)]
(case projectCommand (ConvertProject convertProject)
Expand Down
8 changes: 4 additions & 4 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import Axel.Haskell.Project(buildProject,convertProject,formatProject,runProject
import Axel.Parse.Args(Command(FileCommand,ProjectCommand,Version),FileCommand(ConvertFile,RunFile,FormatFile),ProjectCommand(ConvertProject,FormatProject,RunProject),commandParserInfo)
import Control.Monad(void)
import qualified Data.Map as Map(empty)
import qualified Effectful as Eff
import qualified Effectful.State.Static.Local as Eff
import Options.Applicative(execParser)
import qualified Polysemy as Sem
import qualified Polysemy.State as Sem
import Prelude hiding (putStrLn)
app :: () => ((->) Command (Sem.Sem AppEffs ()))
app (FileCommand fileCommand) = (case fileCommand of {(ConvertFile filePath) -> (void (convertFileInPlace filePath));(FormatFile filePath) -> (formatFileInPlace filePath);(RunFile filePath) -> (void (Sem.evalState Map.empty (withGhci (transpileFileInPlace filePath))))})
app :: () => ((->) Command (Eff.Eff AppEffs ()))
app (FileCommand fileCommand) = (case fileCommand of {(ConvertFile filePath) -> (void (convertFileInPlace filePath));(FormatFile filePath) -> (formatFileInPlace filePath);(RunFile filePath) -> (void (Eff.evalState Map.empty (withGhci (transpileFileInPlace filePath))))})
app (ProjectCommand projectCommand) = (case projectCommand of {ConvertProject -> convertProject;FormatProject -> formatProject;RunProject -> ((>>) buildProject runProject)})
app Version = (putStrLn ((<>) "Axel version " axelVersion))
main :: () => (IO ())
Expand Down
39 changes: 25 additions & 14 deletions axel.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: f70b6a6d1728e78ab4f4dfaca73312b96a6d0cc77b7b10b60851e5216c698d96
-- hash: 16a2f236cab672265c3e9c61bc8aa1cae5c514a879b3e109a31e037b80289124

name: axel
version: 0.0.13
Expand All @@ -25,7 +25,6 @@ extra-source-files:
scripts/ghcid.sh
scripts/lint.sh
scripts/onHsFiles.sh
scripts/stackProfile.sh
scripts/test.sh
data-files:
resources/new-project-template/app/Main.axel
Expand Down Expand Up @@ -100,6 +99,7 @@ library
FlexibleContexts
FlexibleInstances
FunctionalDependencies
GADTs
GeneralizedNewtypeDeriving
InstanceSigs
KindSignatures
Expand All @@ -108,13 +108,14 @@ library
MultiWayIf
NoImplicitPrelude
OverloadedStrings
PolyKinds
RankNTypes
ScopedTypeVariables
StandaloneDeriving
TupleSections
TypeApplications
TypeFamilies
TypeOperators
ghc-options: -Weverything -Wno-all-missed-specialisations -Wno-implicit-prelude -Wno-missed-specialisations -Wno-missing-deriving-strategies -Wno-missing-export-lists -Wno-missing-import-lists -Wno-missing-local-signatures -Wno-missing-kind-signatures -Wno-missing-safe-haskell-mode -Wno-monomorphism-restriction -Wno-prepositive-qualified-module -Wno-safe -Wno-unsafe -Wno-unused-packages -optP-Wno-nonportable-include-path -O2 -fplugin=Polysemy.Plugin -flate-specialise -fspecialise-aggressively
ghc-options: -Weverything -Wno-all-missed-specialisations -Wno-implicit-prelude -Wno-missed-specialisations -Wno-missing-deriving-strategies -Wno-missing-export-lists -Wno-missing-import-lists -Wno-missing-local-signatures -Wno-missing-kind-signatures -Wno-missing-safe-haskell-mode -Wno-monomorphism-restriction -Wno-prepositive-qualified-module -Wno-safe -Wno-unsafe -Wno-unused-packages -optP-Wno-nonportable-include-path -O2 -fplugin=Effectful.Plugin
build-tool-depends:
hpack:hpack
, tasty-discover:tasty-discover
Expand All @@ -125,6 +126,10 @@ library
, bytestring ==0.11.3.1
, containers ==0.6.5.1
, directory ==1.3.6.2
, effectful ==1.1.0.0
, effectful-core ==1.1.0.0
, effectful-plugin ==1.0.0.0
, effectful-th ==1.0.0.0
, extra ==1.7.10
, filepath ==1.4.2.2
, ghcid ==0.8.7
Expand All @@ -138,8 +143,6 @@ library
, megaparsec ==9.2.1
, mono-traversable ==1.0.15.3
, optparse-applicative ==0.17.0.0
, polysemy ==1.7.1.0
, polysemy-plugin ==0.4.3.1
, prettyprinter ==1.7.1
, process ==1.6.13.2
, profunctors ==5.6.2
Expand Down Expand Up @@ -179,6 +182,7 @@ executable axel
FlexibleContexts
FlexibleInstances
FunctionalDependencies
GADTs
GeneralizedNewtypeDeriving
InstanceSigs
KindSignatures
Expand All @@ -187,13 +191,14 @@ executable axel
MultiWayIf
NoImplicitPrelude
OverloadedStrings
PolyKinds
RankNTypes
ScopedTypeVariables
StandaloneDeriving
TupleSections
TypeApplications
TypeFamilies
TypeOperators
ghc-options: -Weverything -Wno-all-missed-specialisations -Wno-implicit-prelude -Wno-missed-specialisations -Wno-missing-deriving-strategies -Wno-missing-export-lists -Wno-missing-import-lists -Wno-missing-local-signatures -Wno-missing-kind-signatures -Wno-missing-safe-haskell-mode -Wno-monomorphism-restriction -Wno-prepositive-qualified-module -Wno-safe -Wno-unsafe -Wno-unused-packages -optP-Wno-nonportable-include-path -O2 -fplugin=Polysemy.Plugin -flate-specialise -fspecialise-aggressively -threaded -rtsopts -with-rtsopts=-N
ghc-options: -Weverything -Wno-all-missed-specialisations -Wno-implicit-prelude -Wno-missed-specialisations -Wno-missing-deriving-strategies -Wno-missing-export-lists -Wno-missing-import-lists -Wno-missing-local-signatures -Wno-missing-kind-signatures -Wno-missing-safe-haskell-mode -Wno-monomorphism-restriction -Wno-prepositive-qualified-module -Wno-safe -Wno-unsafe -Wno-unused-packages -optP-Wno-nonportable-include-path -O2 -fplugin=Effectful.Plugin -threaded -rtsopts -with-rtsopts=-N
build-tool-depends:
hpack:hpack
, tasty-discover:tasty-discover
Expand All @@ -205,6 +210,10 @@ executable axel
, bytestring ==0.11.3.1
, containers ==0.6.5.1
, directory ==1.3.6.2
, effectful ==1.1.0.0
, effectful-core ==1.1.0.0
, effectful-plugin ==1.0.0.0
, effectful-th ==1.0.0.0
, extra ==1.7.10
, filepath ==1.4.2.2
, ghcid ==0.8.7
Expand All @@ -218,8 +227,6 @@ executable axel
, megaparsec ==9.2.1
, mono-traversable ==1.0.15.3
, optparse-applicative ==0.17.0.0
, polysemy ==1.7.1.0
, polysemy-plugin ==0.4.3.1
, prettyprinter ==1.7.1
, process ==1.6.13.2
, profunctors ==5.6.2
Expand Down Expand Up @@ -283,6 +290,7 @@ test-suite axel-test
FlexibleContexts
FlexibleInstances
FunctionalDependencies
GADTs
GeneralizedNewtypeDeriving
InstanceSigs
KindSignatures
Expand All @@ -291,13 +299,14 @@ test-suite axel-test
MultiWayIf
NoImplicitPrelude
OverloadedStrings
PolyKinds
RankNTypes
ScopedTypeVariables
StandaloneDeriving
TupleSections
TypeApplications
TypeFamilies
TypeOperators
ghc-options: -Weverything -Wno-all-missed-specialisations -Wno-implicit-prelude -Wno-missed-specialisations -Wno-missing-deriving-strategies -Wno-missing-export-lists -Wno-missing-import-lists -Wno-missing-local-signatures -Wno-missing-kind-signatures -Wno-missing-safe-haskell-mode -Wno-monomorphism-restriction -Wno-prepositive-qualified-module -Wno-safe -Wno-unsafe -Wno-unused-packages -optP-Wno-nonportable-include-path -O2 -fplugin=Polysemy.Plugin -flate-specialise -fspecialise-aggressively -threaded -rtsopts -with-rtsopts=-N
ghc-options: -Weverything -Wno-all-missed-specialisations -Wno-implicit-prelude -Wno-missed-specialisations -Wno-missing-deriving-strategies -Wno-missing-export-lists -Wno-missing-import-lists -Wno-missing-local-signatures -Wno-missing-kind-signatures -Wno-missing-safe-haskell-mode -Wno-monomorphism-restriction -Wno-prepositive-qualified-module -Wno-safe -Wno-unsafe -Wno-unused-packages -optP-Wno-nonportable-include-path -O2 -fplugin=Effectful.Plugin -threaded -rtsopts -with-rtsopts=-N
build-tool-depends:
hpack:hpack
, tasty-discover:tasty-discover
Expand All @@ -309,6 +318,10 @@ test-suite axel-test
, bytestring ==0.11.3.1
, containers ==0.6.5.1
, directory ==1.3.6.2
, effectful ==1.1.0.0
, effectful-core ==1.1.0.0
, effectful-plugin ==1.0.0.0
, effectful-th ==1.0.0.0
, extra ==1.7.10
, filepath ==1.4.2.2
, ghcid ==0.8.7
Expand All @@ -322,8 +335,6 @@ test-suite axel-test
, megaparsec ==9.2.1
, mono-traversable ==1.0.15.3
, optparse-applicative ==0.17.0.0
, polysemy ==1.7.1.0
, polysemy-plugin ==0.4.3.1
, prettyprinter ==1.7.1
, process ==1.6.13.2
, profunctors ==5.6.2
Expand Down
16 changes: 8 additions & 8 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ ghc-options:
- -Wno-unsafe
- -Wno-unused-packages
- -optP-Wno-nonportable-include-path # https://github.com/haskell/cabal/issues/4739

# https://github.com/polysemy-research/polysemy#necessary-language-extensions
- -O2
- -fplugin=Polysemy.Plugin
- -flate-specialise
- -fspecialise-aggressively
- -fplugin=Effectful.Plugin
build-tools:
- hpack:hpack
- tasty-discover:tasty-discover
Expand All @@ -44,6 +40,10 @@ dependencies:
- bytestring ==0.11.3.1
- containers ==0.6.5.1
- directory ==1.3.6.2
- effectful ==1.1.0.0
- effectful-core ==1.1.0.0
- effectful-plugin ==1.0.0.0
- effectful-th ==1.0.0.0
- extra ==1.7.10
- filepath ==1.4.2.2
- ghcid ==0.8.7
Expand All @@ -57,8 +57,6 @@ dependencies:
- megaparsec ==9.2.1
- mono-traversable ==1.0.15.3
- optparse-applicative ==0.17.0.0
- polysemy ==1.7.1.0
- polysemy-plugin ==0.4.3.1
- prettyprinter ==1.7.1
- process ==1.6.13.2 # https://www.reddit.com/r/haskellquestions/comments/uj759w/ghc_922_build_error
- profunctors ==5.6.2
Expand Down Expand Up @@ -93,6 +91,7 @@ default-extensions:
- FlexibleContexts
- FlexibleInstances
- FunctionalDependencies
- GADTs
- GeneralizedNewtypeDeriving
- InstanceSigs
- KindSignatures
Expand All @@ -101,11 +100,12 @@ default-extensions:
- MultiWayIf
- NoImplicitPrelude
- OverloadedStrings
- PolyKinds # Required by `Polysemy.makeSem`
- RankNTypes
- ScopedTypeVariables
- StandaloneDeriving
- TupleSections
- TypeApplications
- TypeFamilies
- TypeOperators
library:
source-dirs: src
Expand Down
2 changes: 1 addition & 1 deletion scripts/onHsFiles.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
find app src test -iname "*.hs" ! -path "app/Main.hs" ! -path "src/Axel/Parse/Args.hs" ! -path "src/Axel.hs" ! -path "src/Axel/Haskell/Macros.hs" -print0 | xargs -0 $@
find app src test -iname "*.hs" ! -path "app/Main.hs" ! -path "src/Axel/Parse/Args.hs" ! -path "src/Axel.hs" ! -path "src/Axel/Haskell/Macros.hs" -print0 | xargs -0 "$@"
1 change: 0 additions & 1 deletion src/Axel/AST.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}

Expand Down
6 changes: 3 additions & 3 deletions src/Axel/Eff.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Axel.Eff where

import qualified Polysemy as Sem
import Effectful ((:>>), Eff)

type Callback effs fn a
= forall openEffs. (Sem.Members effs openEffs) =>
fn (Sem.Sem openEffs a)
= forall openEffs. (effs :>> openEffs) =>
fn (Eff openEffs a)
10 changes: 5 additions & 5 deletions src/Axel/Eff/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import Axel.Eff.Random (Random, runRandom)
import Axel.Eff.Resource (Resource, runResource)
import Axel.Eff.Time (Time, runTime)

import qualified Polysemy as Sem
import qualified Polysemy.Error as Sem
import qualified Effectful as Eff
import qualified Effectful.Error.Static as Eff

type AppEffs
= '[ Sem.Error Error, Log, Console, FileSystem, Ghci, Process, Resource, Random, Time, Sem.Embed IO]
= '[ Eff.Error Error, Log, Console, FileSystem, Ghci, Process, Resource, Random, Time, Eff.IOE]

runApp :: Sem.Sem AppEffs a -> IO a
runApp :: Eff.Eff AppEffs a -> IO a
runApp =
Sem.runM .
Eff.runEff .
runTime .
runRandom .
runResource .
Expand Down
27 changes: 13 additions & 14 deletions src/Axel/Eff/Console.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}

module Axel.Eff.Console where
Expand All @@ -9,29 +7,30 @@ import Axel.Prelude
import qualified Data.Text as T
import qualified Data.Text.IO as T

import qualified Polysemy as Sem
import Effectful ((:>))
import qualified Effectful as Eff
import qualified Effectful.Dispatch.Dynamic as Eff
import qualified Effectful.TH as Eff

import qualified System.Console.ANSI as ANSI (getTerminalSize)

data Console m a where
data Console :: Eff.Effect where
GetTerminalSize :: Console m (Maybe (Int, Int))
PutStr :: Text -> Console m ()

Sem.makeSem ''Console
Eff.makeEffect ''Console

runConsole ::
(Sem.Member (Sem.Embed IO) effs)
=> Sem.Sem (Console ': effs) a
-> Sem.Sem effs a
runConsole :: (Eff.IOE :> effs) => Eff.Eff (Console ': effs) a -> Eff.Eff effs a
runConsole =
Sem.interpret $ \case
GetTerminalSize -> Sem.embed ANSI.getTerminalSize
PutStr str -> Sem.embed $ T.putStr str
Eff.interpret $ \_ ->
\case
GetTerminalSize -> Eff.liftIO ANSI.getTerminalSize
PutStr str -> Eff.liftIO $ T.putStr str

putStrLn :: (Sem.Member Console effs) => Text -> Sem.Sem effs ()
putStrLn :: (Console :> effs) => Text -> Eff.Eff effs ()
putStrLn = putStr . (<> "\n")

putHorizontalLine :: (Sem.Member Console effs) => Sem.Sem effs ()
putHorizontalLine :: (Console :> effs) => Eff.Eff effs ()
putHorizontalLine = do
maybeTerminalSize <- getTerminalSize
case maybeTerminalSize of
Expand Down
Loading

0 comments on commit c2cabd3

Please sign in to comment.