No subject
Sun Oct 23 10:51:38 CEST 2011
all that is lower on the picture. Therefore, the conditional
`instance (Show a, CRing a) =>' and 'where'
is written only once.
In the existing language, I need to write this conditional 6 times.
Union instance decl proposal
----------------------------
It is a generalization for inhereted decl.
instances (cond_1, ..., cond_n) -- of the type parameters a_1 ... a_m
=>
<typeTuple> (<params>) has {<conclInstList>}
where
<implement operations for each member of <conclInstList>.
It differs from the old instance declaration in that
1) it unions several old declarations having the same conditional part,
2) each member of <conclInstList> can be conditional,
3) in <conclInstList> it can be skipped any instance which is inherited
by some other member in this list.
<params> is a subset of {a_1 ... a_m},
<typeTuple> (<params>)
is a tuple of type expressions, as in old declaration,
for example, `(a, b)', `Vector a', `[(a,b), Vector a]'.
It is the argument for the conclusion instance declarations.
<conclInstList> is a list of inst-members separated by comma.
Each member of <conclInstList> is either an
old conclusion instance declaration
or a conditional declaration.
Example.
In the situtation of Picture 1, I need to declare
instance (Show a, CRing a) =>
(Pol a) has { CRing, if (has a Field) then ERing }
where
<define operations for Set (Pol a)>
<define operations for AddSemigroup (Pol a)>
...
<define operations for CRing (Polynomial a)>
<define operations for ERing (Pol a)> -- this part has the
-- additional condition (Field a)
Its meaning is that the complier extends this into several `old'
instance declarations:
instance (Show a, CRing a) => Set (Pol a) where
<define operations for Set (Pol a)>
...
instance (Show a, CRing a) => CRing (Pol a) where
<define operations for Set (Pol a)>
instance (Show a, Field a) => ERing (Pol a) where
<define operations for ERing (Pol a)>
(in the last decl `Field a' has been moved to LHS).
In this example <typeTuple> === (Pol a).
For bi-parametric instances, the concusion part may be, for example
=>
[a, Pol a] has {Foo1, Foo2} ...
This means the two instance assertions Foo1 a (Pol a), Foo a (Pol a),
and `[a, Pol a]' is the agrument tuple for the instance conclusions.
This is a draft proposal. If the idea is accepted, some generalizations
and corrections are expected.
Regards,
-----------------
Serge Mechveliani
mechvel at botik.ru
More information about the Glasgow-haskell-users
mailing list