Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write the qualified name of a symbol in Haskell?

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

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.<*>

and Test2.hs:

module Test2
where
(<*>) = 3

But trying to compile results in an error message:

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

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

How can I refer to a symbolic name defined in a module imported by import qualified?

like image 793
Norman Ramsey Avatar asked Apr 12 '09 02:04

Norman Ramsey


People also ask

What is qualified in Haskell?

The keyword qualified means that symbols in the imported modules are not imported into the unqualified (prefixless) namespace.

What does -> mean in Haskell?

(->) is often called the "function arrow" or "function type constructor", and while it does have some special syntax, there's not that much special about it. It's essentially an infix type operator. Give it two types, and it gives you the type of functions between those types.

What is Haskell operator?

Haskell provides special syntax to support infix notation. An operator is a function that can be applied using infix syntax (Section 3.4), or partially applied using a section (Section 3.5).

What is colon Haskell?

In Haskell, the colon operator is used to create lists (we'll talk more about this soon). This right-hand side says that the value of makeList is the element 1 stuck on to the beginning of the value of makeList .


2 Answers

try

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.\\)

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.

like image 94
newacct Avatar answered Oct 19 '22 07:10

newacct


Remember that we import symbols wrapped parens. E.g.

import T ((<*>))

so importing qualified is the same:

import qualified T as Q

main = print (Q.<*>)
like image 26
Don Stewart Avatar answered Oct 19 '22 06:10

Don Stewart