Agda:函数解析错误

时间:2018-08-25 21:52:07

标签: parsing agda

我是agda的新手,并遵循小MLer一书中的一个简单示例。谁能帮助我找出为什么编译器给我一个解析错误?

谢谢

data Shish (a : Set) : Set where
  Bottom : a → Shish a
  Onion : Shish a → Shish a
  Lamb : Shish a → Shish a
  Tomato : Shish a → Shish a

data Rod : Set where
  Dagger : Rod
  Fork : Rod
  Sword : Rod

data Plate : Set where
  Gold-plate : Plate
  Silver-plate : Plate
  Brass-plate : Plate

what_bottom : Shish (a : Set) → Bool
what_bottom (Bottom x) → x
what_bottom (Onion x) → what_bottom x
what_bottom (Lamb x) → what_bottom x
what_bottom (Tomato x) → what_bottom x



/Volumes/Little/mko_io/cat/tmp/mler.agda:54,24-24
        /Volumes/Little/mko_io/cat/tmp/mler.agda:54,24: Parse error
        :<ERROR>
         Set) → Bool
        what_bottom (Bott...

2 个答案:

答案 0 :(得分:1)

正确定义了数据类型定义,但这不是在Agda中定义函数的方式。 Dependent types at work

是一个很好的入门教程

函数用等号定义。

inline

此外,必须先隐式或显式声明依赖类型。

id : {A : Set} → A → A
id a = a

最后,无法使用返回类型what_bottom : {A : Set} → Shish A → ... 定义该函数。它可以具有类型Bool

答案 1 :(得分:0)

作为另一个语法点,在Agda中,下划线是mixfix参数的占位符:what_bottom是mixfix名称,其参数在whatbottom之间。因此,您最终会得到一个用作what (Onion $ Lamb $ Bottom) bottom的函数,而这可能并不是您想要的。如果您感到多余,只需将其命名为whatBottomwhat‿bottom