Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting type-operators from modules

How do you export type-operators? Considering they can clash with normal operators, there must be a special syntax if it's possible.

like image 440
Shou Avatar asked Mar 20 '15 07:03

Shou


People also ask

How do I export TypeScript types?

Use a named export to export a type in TypeScript, e.g. export type Person = {} . The exported type can be imported by using a named import as import {Person} from './another-file' . You can have as many named exports as necessary in a single file.

How do I export functions in TypeScript?

Use named exports to export a function in TypeScript, e.g. export function sum() {} . The exported function can be imported by using a named import as import {sum} from './another-file' . You can use as many named exports as necessary in a single file.

What is module export?

Module exports are the instructions that tell Node. js which bits of code (functions, objects, strings, etc.) to export from a given file so that other files are allowed to access the exported code.


1 Answers

I found the answer in section 7.4.4 of the GHC User's Guide, which states:

There is now some potential ambiguity in import and export lists; for example if you write import M( (+) ) do you mean the function (+) or the type constructor (+)? The default is the former, but with -XExplicitNamespaces (which is implied by -XExplicitTypeOperators) GHC allows you to specify the latter by preceding it with the keyword type, thus:

import M( type (+) )

Although it doesn't seem like you actually need to specify -XExplicitNamespaces, maybe -XExplicitTypeOperators is a typo meant to be -XTypeOperators. Some more empirical evidence for this:

★ → :set -XExplicitTypeOperators
Some flags have not been recognized: -XExplicitTypeOperators
like image 88
Shou Avatar answered Sep 18 '22 09:09

Shou