'[]来自哪里,在哪里声明?

时间:2018-08-11 23:43:50

标签: haskell types data-kinds

freer-simple中的示例代码

{-# LANGUAGE GADTs #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}
module Console where

import Control.Monad.Freer
import Control.Monad.Freer.Error
import Control.Monad.Freer.State
import Control.Monad.Freer.Writer
import System.Exit hiding (ExitCode(ExitSuccess))

--------------------------------------------------------------------------------
                                                             -- Effect Model --
--------------------------------------------------------------------------------
data Console r where
    PutStrLn    :: String -> Console ()
    GetLine     :: Console String
    ExitSuccess :: Console ()

putStrLn' :: Member Console effs => String -> Eff effs ()
putStrLn' = send . PutStrLn

getLine' :: Member Console effs => Eff effs String
getLine' = send GetLine

exitSuccess' :: Member Console effs => Eff effs ()
exitSuccess' = send ExitSuccess

--------------------------------------------------------------------------------
                                                    -- Effectful Interpreter --
--------------------------------------------------------------------------------
runConsole :: Eff '[Console, IO] a -> IO a
runConsole = runM . interpretM (\case
    PutStrLn msg -> putStrLn msg
    GetLine -> getLine
    ExitSuccess -> exitSuccess)

在Eff'[Console,IO]中,我不知道奇怪的外观'[...]来自何处。

我知道它为解释器声明了一个效果列表,但在哪里声明了?

我四处浏览该库的源代码,但看不到任何我认为是“构造函数”的东西。

它是Haskell的功能吗,它是否来自底层的类型库?

对其目的更严格的描述是什么?

0 个答案:

没有答案