在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):lexi-lambda/freer-simple开源软件地址(OpenSource Url):https://github.com/lexi-lambda/freer-simple开源编程语言(OpenSource Language):Haskell 100.0%开源软件介绍(OpenSource Introduction):freer-simple — a friendly effect system for HaskellThe The key features of
For more details, see the package documentation on Hackage. Code example{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
import qualified Prelude
import qualified System.Exit
import Prelude hiding (putStrLn, getLine)
import Control.Monad.Freer
import Control.Monad.Freer.TH
import Control.Monad.Freer.Error
import Control.Monad.Freer.State
import Control.Monad.Freer.Writer
--------------------------------------------------------------------------------
-- Effect Model --
--------------------------------------------------------------------------------
data Console r where
PutStrLn :: String -> Console ()
GetLine :: Console String
ExitSuccess :: Console ()
makeEffect ''Console
--------------------------------------------------------------------------------
-- Effectful Interpreter --
--------------------------------------------------------------------------------
runConsole :: Eff '[Console, IO] a -> IO a
runConsole = runM . interpretM (\case
PutStrLn msg -> Prelude.putStrLn msg
GetLine -> Prelude.getLine
ExitSuccess -> System.Exit.exitSuccess)
--------------------------------------------------------------------------------
-- Pure Interpreter --
--------------------------------------------------------------------------------
runConsolePure :: [String] -> Eff '[Console] w -> [String]
runConsolePure inputs req = snd . fst $
run (runWriter (runState inputs (runError (reinterpret3 go req))))
where
go :: Console v -> Eff '[Error (), State [String], Writer [String]] v
go (PutStrLn msg) = tell [msg]
go GetLine = get >>= \case
[] -> error "not enough lines"
(x:xs) -> put xs >> pure x
go ExitSuccess = throwError () AcknowledgementsThe |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论