Mrk Sef
Mrk Sef

Reputation: 8022

Purescript Import infix type constrctor

Here, \/ is from Data.Either.

This example is copied from the link above:

f :: (Int \/ String \/ Boolean) -> String
f = show \/ identity \/ if _ then "Yes" else "No"

What does the import statement look like?

Upvotes: 0

Views: 135

Answers (1)

Fyodor Soikin
Fyodor Soikin

Reputation: 80754

Here you need to import both the type \/ and the value \/.

The syntax for importing type operators is type (\/). The prefix type is necessary for disambiguation - that is, to let the compiler know that you're importing the type, not the value that might have the same name.

And the syntax for importing the value is as usual.

So the whole import would look like this:

import Data.Either.Nested (type (\/), (\/))

In conclusion, I would recommend using your IDE integration (for example, here's a VSCode extension) to insert imports for you. That way you don't have to know the precise syntax.

Upvotes: 4

Related Questions