相关疑难解决方法(0)

导航和修改在Haskell中的Free monad上构建的AST

我试图根据我在网上阅读的一些有用的文献,使用Free monad构建AST.

我有一些关于在实践中使用这些AST的问题,我已经归结为以下示例.

假设我的语言允许以下命令:

{-# LANGUAGE DeriveFunctor #-}

data Command next
  = DisplayChar Char next
  | DisplayString String next
  | Repeat Int (Free Command ()) next
  | Done
  deriving (Eq, Show, Functor)
Run Code Online (Sandbox Code Playgroud)

我手动定义了Free monad样板:

displayChar :: Char -> Free Command ()
displayChar ch = liftF (DisplayChar ch ())

displayString :: String -> Free Command ()
displayString str = liftF (DisplayString str ())

repeat :: Int -> Free Command () -> Free Command ()
repeat times block = liftF (Repeat times …
Run Code Online (Sandbox Code Playgroud)

haskell abstract-syntax-tree free-monad

11
推荐指数
3
解决办法
1540
查看次数

标签 统计

abstract-syntax-tree ×1

free-monad ×1

haskell ×1