Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • P prime
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 128
    • Issues 128
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 0
    • Merge requests 0
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • HaskellHaskell
  • prime
  • Wiki
  • infix type constructors

infix type constructors · Changes

Page history
Edit InfixTypeConstructors authored Apr 24, 2008 by Simon Peyton Jones's avatar Simon Peyton Jones
Show whitespace changes
Inline Side-by-side
infix-type-constructors.md
View page @ d69f08a4
......@@ -23,6 +23,39 @@ And `type` gets an extra production:
(modulo [FixityResolution](fixity-resolution)). Also, there are obvious changes to the grammar for `type`, `data`, and `newtype` declarations.
Secondly, I propose to allow varsyms to be used as type *constructors*. For example, currently "+" is a varsym, so at the type level it'd behave like a type *variable*
```wiki
data T (+) = MkT (Int + Int)
```
It's not impossible that this might be useful, although the binding site looks clumsy. But it misses a much more useful opportunity. What we *want* is to say
```wiki
data a + b = Left a | Right b
```
That is, we want to define the type *constructor*`(+)`. Currently we have to use the clumsy `:+` notation:
```wiki
data a :+ b = Left a | Right b
```
Yuk. **So I propose that varsyms can be used as type constructors, and not as type variables.**
You may say that is inconsistent, because at the value level you have to start data constructors with a ":". But the type level is already funny. The whole type-family idea (beginning with type synonyms) defines things that begin with a capital letter, but which (unlike data constructors) are not head normal forms. By the time we have full type-synonym families, they really are \*functions\* as much as any value-level function is.
Some people use Haskell as a laboratory in which to write their cunning type ideas. In mathematics, operators are invariably top-level type constructors (think of the type a+b). Mirroring this in Haskell would make the transcription more elegantly direct.
I can't think of any down-sides, except the slight loss of consistency ("the hobgoblin of tiny minds").
## References
- [ Infix type constructors, classes, and type variables](http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions.html#infix-tycons) in the GHC User's Guide.
......
Clone repository Edit sidebar
  • Arrows
  • BangPatterns
  • DeepSeq
  • ExistentialQuantification
  • ExplicitForall
  • FlexibleContexts
  • FlexibleInstances
  • ForeignFunctionInterface
  • FunctionalDependencies
  • GADTs
  • ImplicitParams
  • IncoherentInstances
  • KindAnnotations
  • LamdaCase
  • MultiParamTypeClasses dilemma
View All Pages