我如何在Haskell中编写符号的限定名称? [英] How do I write the qualified name of a symbol in Haskell?

查看:146
本文介绍了我如何在Haskell中编写符号的限定名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要使用相同的中缀运算符(<> )的两个不同Haskell模块之间发生名称冲突。 Haskell 98报告称,

I've got a name clash between two different Haskell modules that want to use the same infix operator (<*>). The Haskell 98 report says that

modid.varsym

是允许的,但我无法让它工作。在这里完整的是 Test.hs

is permitted, but I can't get it to work. In their entirety here are Test.hs:

module Test
where

import qualified Test2 as T

three = T.<*>

Test2.hs

module Test2
where
(<*>) = 3

但试图编译错误信息的结果:

But trying to compile results in an error message:

Test.hs:6:12: parse error on input `T.<*>'

我试过 T。(*),但这也不管用。

I tried T.(<*>) but that doesn't work either.

如何引用由导入限定

推荐答案

three = (T.<*>)

将中缀运算符定义为整数是奇怪的。让我们考虑 \\ (设置差异运算符):

It's weird to define an infix operator as an integer. Let's consider \\ (the set difference operator):

import qualified Data.List as L

foo = [1..5] L.\\ [1..3] -- evaluates to [4,5]
diff = (L.\\)

如上所示, L 。\\ 是一个合格的中缀操作符;它仍然是一个中缀运算符。要将它用作值,你需要在整个事物中放置括号。

As you can see above, L.\\ is a qualified infix operator; and it still works as an infix operator. To use it as a value, you put parentheses around the whole thing.

这篇关于我如何在Haskell中编写符号的限定名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆