代码之家  ›  专栏  ›  技术社区  ›  mko

Agda:函数分析错误

  •  0
  • mko  · 技术社区  · 7 年前

    谢谢你

    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 回复  |  直到 7 年前
        1
  •  1
  •   white_wolf    7 年前

    数据类型定义定义正确,但这不是在Agda中定义函数的方式。一个好的开始教程是 Dependent types at work

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

    此外,依赖类型必须在like之前声明,所以要么隐式声明,要么显式声明。

    what_bottom : {A : Set} → Shish A → ...
    

    最后,不能用返回类型定义该函数 Bool a 不过。

        2
  •  0
  •   Cactus    7 年前

    作为附加的语法点,在Agda中,下划线是mixfix参数的占位符: what_bottom what bottom . 所以你最终会得到一个函数 what (Onion $ Lamb $ Bottom) bottom 这可能不是你想要的。就叫它吧 whatBottom what‿bottom 如果你觉得多余。