Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Agda:名称不明确==\u。它可以指任何一个_Agda - Fatal编程技术网

Agda:名称不明确==\u。它可以指任何一个

Agda:名称不明确==\u。它可以指任何一个,agda,Agda,如果我想处理提供冲突名称的包,例如 module Halp where open import Data.String open import Data.Char open import Data.Bool foo : String -> String -> String foo a b with a == b ... | true = "foo" ... | false = "bar" 导致 Ambiguous name _==_. It

如果我想处理提供冲突名称的包,例如

  module Halp where
  open import Data.String 
  open import Data.Char 
  open import Data.Bool

  foo : String -> String -> String
  foo a b  with a == b
  ... | true = "foo"
  ... | false = "bar"
导致

 Ambiguous name _==_. It could refer to any one of
  Data.String._==_ bound at ...\Data\String.agda:71,1-5
  Data.Char._==_   bound at ...\Data\Char.agda:40,1-5
如果存在歧义,有没有办法让agda弄明白我所说的参数是什么函数

目前,我找到了一种解决方法,可以执行
\u==s\u==Data.String.\u==\ u


还有其他方法吗?

遗憾的是,没有,没有办法让Agda根据参数的类型选择其中一种。Agda只能为构造函数解析不明确的名称

但是,有比使用
\u==s
更好的方法来指定要使用哪一个

  • 您可以指定要导入全局命名空间的函数:

    open import Data.Char
      hiding (_==_)
    open import Data.String
    
    -- or the other way around
    open import Data.Char
      using (Char) -- and other stuff you might need
    open import Data.String
      using (String; _==_) -- etc.
    
  • 您可以在函数中本地打开模块:

    import Data.Char
    import Data.String
    
    test : Type
    test = expr -- use _==_ here
      where
      open Data.String
      -- unqualified names are only available inside expr
    
  • 您可以在另一个模块内本地打开模块:

    module UsesStringEq where
      open Data.String
        using (_==_)
    
      test : Type
      test = expr -- use _==_ here
    
    open UsesStringEq public
    -- make sure that other modules can use unqualified names
    -- from UsesStringEq
    
  • 您可以使用完全限定名:

    test : String → String → String
    test a b = if a Data.String.== b then "OK" else "Bad"
    

您可以通过使用实例参数来实现这一点,实例参数是类型类的Agda替代品。不幸的是,Agda库还没有在编写时考虑到实例参数,因此您必须自己定义Eq类以及Char和String的实例:

open import Data.Bool

open import Data.Char hiding (_==_)
open import Data.String hiding (_==_)

-- The Eq type class
record Eq (A : Set) : Set₁ where
  field
    _==_ : A → A → Bool

-- Instance argument magic
open Eq {{...}}

-- Eq instance for Char
EqChar : Eq Char
EqChar = record { _==_ = Data.Char._==_ }

-- Eq instance for Bool
EqString : Eq String
EqString = record { _==_ = Data.String._==_ }
现在您可以对
Char
Bool
使用

test : Bool
test = ('a' == 'a') ∧ ("foo" == "foo") 
要了解有关实例参数的更多信息,可以在agdawiki()或介绍实例参数的论文()中阅读

目前,我找到了一种解决方法,可以执行
\u==s\u==Data.String.\u==\ u

您还可以在打开模块时重命名绑定:

open import Data.String renaming (_==_ to _==s_)
open import Data.Char renaming (_==_ to _==c_)

好极了!它甚至可以在传递==作为函数参数时工作:
elem-like-eq x xs=any(eq x)xs
\n
是wspace c=elem-like\u==c(toList“\t\n\r”)