Wildcards in type functions
I would like to be able to use wildcards in type synonym family instances, so that I can write:
type instance ErrorAlg (f :>: _) e a = ErrorAlg f e a
Trac metadata
Trac field | Value |
---|---|
Version | 6.10.4 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |
Relates to
Activity
- MartijnVanSteenbergen changed weight to 5
changed weight to 5
- MartijnVanSteenbergen added Tfeature request Trac import labels
added Tfeature request Trac import labels
- Simon Peyton Jones changed milestone to %6.14 branch
changed milestone to %6.14 branch
- Developer
Very reasonable idea. I've added it to our list of type-function feature requests at http://hackage.haskell.org/trac/ghc/wiki/TypeFunctionsStatus
Simon
Continuing this line of thought, instances for this family go hand in hand with instances for this type class:
class MkErrorAlgebra f where mkErrorAlgebra :: ErrorAlg f e a -> ErrorAlgPF f e a
Would it then also make sense to write:
instance MkErrorAlgebra f => MkErrorAlgebra (f :>: _) where mkErrorAlgebra alg (Tag f) = mkErrorAlgebra alg f
?
Just a wild idea which I'm not sure yet I like or dislike. It does fit in with the idea of not making up names if you don't have to. For that reason I also prefer writing
data D :: <kind> where
for GADTs rather than making up arbitrary names for the type arguments. Going even further, this idea can be extended to e.g.data Const a _ = Const a
for normal ADTs.Okay, enough wild ideas for now. :-)
- Ian Lynagh <igloo@earth.li> removed milestone
removed milestone
- Ian Lynagh <igloo@earth.li> changed milestone to %7.0.2
changed milestone to %7.0.2
- Ian Lynagh <igloo@earth.li> changed milestone to %7.2.1
changed milestone to %7.2.1
- Ian Lynagh <igloo@earth.li> changed milestone to %7.4.1
changed milestone to %7.4.1
- Ian Lynagh <igloo@earth.li> changed milestone to %7.6.1
changed milestone to %7.6.1
- Ian Lynagh <igloo@earth.li> changed weight to 3
changed weight to 3
Trac metadata
Trac field Value Priority normal → low - Developer
Trac metadata
Trac field Value CC → eir@seas.upenn.edu - Ian Lynagh <igloo@earth.li> changed milestone to %7.6.2
changed milestone to %7.6.2
- thoughtpolice changed milestone to %7.10.1
changed milestone to %7.10.1
Moving to 7.10.1.
Trac metadata
Trac field Value Component Compiler → Compiler (Type checker) - thoughtpolice removed milestone
removed milestone
Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.
- Jan Stolarek added newcomer label
added newcomer label
How would we resolve things like
type instance Testing (f :>: _) = MyType f type instance Testing (_ :>: g) = MyType g
and other such collisions?
I'm pretty new to GHC - is there an existing resolution order from elsewhere that could be borrowed for this?
I always imagined that
_
will be instantiated internally to a fresh type variable. This means that this feature would mostly affect the parser and renamer and by the time you reach the point when your example collision is checked (FamInst.checkForConflicts
, called fromFamInst.checkFamInstConsistency
) the example code will look like:type instance Testing (f :>: a_1234) = MyType f type instance Testing (a_5678 :>: g) = MyType g
where
a_1234
anda_5678
are fresh type variables.I thought about this a little last night and realised that the resolution should be the same as for unused type variables. Your comment confirms that and gives a few hints on where to get started - so thanks heaps!
- Dave Laing assigned to @dalaing
assigned to @dalaing
dalaing, what is the status of your work? I ask because I have a student who would be interested in implementing this ticket but if you are actively working on this ticket we will look for something else.
- Dave Laing unassigned @dalaing
unassigned @dalaing
jstolarek - sorry I missed you comment - I've been stalled on this for a while as various other things have moved to the front of the queue, so I've unassigned myself for now.
- msosn assigned to @trac-msosn
assigned to @trac-msosn
- Richard Eisenberg mentioned in issue #10586 (closed)
mentioned in issue #10586 (closed)
Trac metadata
Trac field Value Differential revisions - → D1092 Fixing #10586 (closed) led me to add support for wild cards in type/data family instance declarations, see D1092.
@msosn: Sorry for stealing this. As I implemented partial type signatures in the first place, this was less than an hour's worth of work for me.
- Ben Gamari closed
closed
- Maintainer
Trac metadata
Trac field Value Resolution Unresolved → ResolvedFixed You are amazing! Thanks for building this. :-)
- thoughtpolice changed milestone to %8.0.1
changed milestone to %8.0.1
Milestone renamed
- Jan Stolarek mentioned in issue #10982 (closed)
mentioned in issue #10982 (closed)
- Ben Gamari added Plow label
added Plow label