... | ... | @@ -5,33 +5,59 @@ TODO forbid `(:: forall a . a)` (any variables must be in scope), mention wildca |
|
|
## Semantics
|
|
|
|
|
|
|
|
|
|
|
|
The `SignatureSections` language pragma enables the use of the `::` type-signature operator in "type-signature sections" expressions, i.e.
|
|
|
|
|
|
> *aexp* → `(``::`*type*`)`
|
|
|
|
|
|
>
|
|
|
>
|
|
|
> *aexp* → `(` `::` *type* `)`
|
|
|
>
|
|
|
>
|
|
|
|
|
|
|
|
|
where *type* must not have any free (not bound by outer context) type-variables.
|
|
|
|
|
|
|
|
|
|
|
|
**Translation:** The following identity holds
|
|
|
|
|
|
> `(``::`*type*`)` = `\`*x*`->`*x*`::`*type*
|
|
|
|
|
|
>
|
|
|
>
|
|
|
> `(` `::` *type* `)` = `\` *x* `->` *x* `::` *type*
|
|
|
>
|
|
|
>
|
|
|
|
|
|
## Applications
|
|
|
|
|
|
|
|
|
|
|
|
Like Haskell2010 expression type-signatures, type-signature sections are useful to explicitly type expressions to help resolve ambiguous typing (e.g. due to overloading).
|
|
|
|
|
|
|
|
|
### Examples
|
|
|
|
|
|
|
|
|
```
|
|
|
canonDouble::String->StringcanonDouble= show . read -- type errorcanonDouble= show .(::Double). read -- OK
|
|
|
canonDouble :: String -> String
|
|
|
canonDouble = show . read -- type error
|
|
|
canonDouble = show . (:: Double) . read -- OK
|
|
|
```
|
|
|
|
|
|
```
|
|
|
typeRep:: proxy a ->TypeRepdataProxy a =Proxy-- without `SignatureSections`a= typeRep (Proxy::ProxyBool)-- with `SignatureSectionsa= typeRep (::Bool)
|
|
|
typeRep :: proxy a -> TypeRep
|
|
|
data Proxy a = Proxy
|
|
|
|
|
|
-- without `SignatureSections`
|
|
|
a = typeRep (Proxy :: Proxy Bool)
|
|
|
|
|
|
-- with `SignatureSections
|
|
|
a = typeRep (:: Bool)
|
|
|
```
|
|
|
|
|
|
### References
|
|
|
|
|
|
|
|
|
- [\#10803](https://gitlab.haskell.org//ghc/ghc/issues/10803)
|
|
|
- [ http://augustss.blogspot.co.at/2014/04/a-small-haskell-extension.html](http://augustss.blogspot.co.at/2014/04/a-small-haskell-extension.html) |
|
|
\ No newline at end of file |
|
|
- [ http://augustss.blogspot.co.at/2014/04/a-small-haskell-extension.html](http://augustss.blogspot.co.at/2014/04/a-small-haskell-extension.html) |