[GHC] #10794: Extension request: "where" clauses in type signatures
GHC
ghc-devs at haskell.org
Tue Aug 25 22:41:23 UTC 2015
#10794: Extension request: "where" clauses in type signatures
-------------------------------------+-------------------------------------
Reporter: danso | Owner:
Type: feature request | Status: new
Priority: lowest | Milestone:
Component: Compiler (Type | Version: 7.10.2
checker) |
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions:
-------------------------------------+-------------------------------------
Description changed by danso:
Old description:
> Some type signatures could be simplified by separating certain elements,
> either because they are lengthy and can be expressed simpler, to better
> express intention, or because they are repetitive. A "WhereSignatures"
> extension would allow for type signatures like the following:
>
> {{{#!hs
> fold :: f -> [a] -> a
> where f :: a -> a -> a
>
> -- expresses intention more clearly than:
> fold :: (a -> a -> a) -> [a] -> a
>
> union :: a -> a -> a
> where a :: Map.Map k v
>
> -- much shorter/more readable than:
> union :: Map.Map k v -> Map.Map k v -> Map.Map k v
> }}}
>
> Or maybe even:
>
> {{{#!hs
> fmap :: (a -> b) -> f a -> f b
> where (Functor f)
>
> -- arguably prettier than:
> fmap :: (Functor f) => (a -> b) -> f a -> f b
> }}}
>
> This minor syntactic sugar is essentially equivalent to local "type"
> definitions, which provides an advantage of making the type's purpose
> more clear. This seems like a natural development on what the type
> checker can do.
New description:
Some type signatures could be simplified by separating certain elements,
either because they are lengthy and can be expressed simpler, to better
express intention, or because they are repetitive. A "WhereSignatures"
extension would allow for type signatures like the following:
{{{#!hs
fold :: f -> [a] -> a
where f = a -> a -> a
-- expresses intention more clearly than:
fold :: (a -> a -> a) -> [a] -> a
union :: a -> a -> a
where a = Map.Map k v
-- much shorter/more readable than:
union :: Map.Map k v -> Map.Map k v -> Map.Map k v
}}}
Or maybe even:
{{{#!hs
fmap :: (a -> b) -> f a -> f b
where (Functor f)
-- arguably prettier than:
fmap :: (Functor f) => (a -> b) -> f a -> f b
}}}
This minor syntactic sugar is essentially equivalent to local "type"
definitions, which provides an advantage of making the type's purpose more
clear. This seems like a natural development on what the type checker can
do.
--
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10794#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list