[Haskell-beginners] How to get qualifiers into type
Kim-Ee Yeoh
ky3 at atamo.com
Thu Jan 17 16:32:50 CET 2013
On Thu, Jan 17, 2013 at 8:40 PM, Rustom Mody <rustompmody at gmail.com> wrote:
> And I need to do things like
>
> type Vertex = Ix a => a
> (so that a vertex can be used to index an adjacency-list-array)
>
Two things seem to be going on:
(1) you're trying to define a data type using "type" and not "data"+class
instances. Recall that the "type" declares a type /synonym/, and while type
synonyms seem to behave like CPP-style macros, they aren't.
> That is to say that whenever 'Vertex' appears in a type signature, the Ix
> should 'float' out to the qualifier list
>
(2) you're trying to save on keyboarding by using Vertex as a CPP-style
macro that expands in the "smart" way you just described. Something that
has been requested before is collapsing a list of constraints into just one
(search haskell-cafe archives and also see "No Module Abstraction" of [1]).
The larger the number of constraints, i.e. (A x) expands out to (B x, C x,
D x, ...) the greater the need for such a feature. But there's no benefit
to be gained here.
(3) you're trying to improve readability of code because "Ix a => a" isn't
explicit that type variable "a" is a vertex. Nothing stops you from writing
"Ix vertex => vertex" however. See [2].
[1] http://lukepalmer.wordpress.com/2010/03/19/haskells-big-three/
[2]
http://www.amateurtopologist.com/blog/2011/10/11/name-your-type-variables/
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130117/ed3db080/attachment.htm>
More information about the Beginners
mailing list