小编hen*_*ing的帖子

键入的表达式解析器

我正在尝试在Haskell中创建一个类型化的表达式解析器,到目前为止效果很好,但我目前正在努力实现更高阶的函数.我把这个问题简化为一个简单的例子:

{-# LANGUAGE TypeFamilies,GADTs,FlexibleContexts,RankNTypes #-}

-- A function has an argument type and a result type
class Fun f where
  type FunArg f
  type FunRes f

-- Expressions are either constants of function applications
data Expr a where
  Const :: a -> Expr a
  App :: Fun f => f -> FunArg f -> Expr (FunRes f)

-- A very simple function
data Plus = Plus

-- Which takes two integer expressions and returns an integer expression
instance Fun Plus …
Run Code Online (Sandbox Code Playgroud)

haskell

7
推荐指数
1
解决办法
244
查看次数

标签 统计

haskell ×1