Integrating typeclass with covariance support

43 views
Skip to first unread message

Alois Cochard

unread,
Feb 3, 2013, 8:45:48 AM2/3/13
to shapel...@googlegroups.com, Miles Sabin
Hey folks,

Some times ago I proposed a bunch of type class to be added:

Only the last was added, so I'm still relaying on some custom shapeless build on experimental project, and now I currently writing a small introduction to use HList to write DSL, and I one more time face the limitation on not having covariance when working with ADT in HList.

So could someone show how to achieve something similar to this without those covariant typeclass?

Of course the example is not complete, because once this work, I want 'route' to take a second which is a function take a type transformed like this for example:
Name :: PathElement[Int] :: HNil => filtering Name, and then using NatTRel to extract inner type => Int :: HNil

I would love to be proved wrong, but I really think we need those typeclass to achive something like this, and this can be really useful to write polytypic DSL based on ADT.

Thanks

Alois Cochard

Miles Sabin

unread,
Feb 11, 2013, 9:58:26 PM2/11/13
to Alois Cochard, shapel...@googlegroups.com
OK, that example is compelling for adding variance support to
UnaryTCConstraint. If you had that, would you still need a natural
transformation witness variant with variance support?

Jason, you've had fun with this sort of "variance polymorphism" issue
in the past I think? Any advice?

Cheers,


Miles

--
Miles Sabin
tel: +44 7813 944 528
skype: milessabin
gtalk: mi...@milessabin.com
g+: http://www.milessabin.com
http://twitter.com/milessabin

Miles Sabin

unread,
Feb 12, 2013, 11:35:52 AM2/12/13
to Alois Cochard, shapel...@googlegroups.com
On Mon, Feb 11, 2013 at 7:58 PM, Miles Sabin <mi...@milessabin.com> wrote:
> OK, that example is compelling for adding variance support to
> UnaryTCConstraint.

Actually, after sleeping on it and a bit more thought, I take that
back. The constraint you want can be encoded via the existing
LUBConstraint,

import LUBConstraint._

def route[L <: HList : <<:[PathElement[_]]#λ](path: L)(implicit fn:
FilterNot[L, Name]) = path.filterNot[Name]

ie. all the elements are <: PathElement[_].

Does this work for you in context?
Reply all
Reply to author
Forward
0 new messages