[feature-proposal] Type class for 'natural transformation'

43 views
Skip to first unread message

Alois Cochard

unread,
Jul 2, 2012, 3:48:00 PM7/2/12
to shapel...@googlegroups.com
Hi all,

Here is a feature which make possible to transform an HList type to an other one, for example it can be used to 'convert' 'List[String] :: List[Int]' to 'Option[String] :: Option[Int]':

Implemantation available here:

By using 'Id' it's too possible to 'extract' type from a type constructor, please looks at test for more details.

Don't hesitate to propose a better name!

Cheers,

Miles Sabin

unread,
Jul 3, 2012, 3:59:40 AM7/3/12
to shapel...@googlegroups.com
On Mon, Jul 2, 2012 at 8:48 PM, Alois Cochard <alois....@gmail.com> wrote:
> Hi all,
>
> Here is a feature which make possible to transform an HList type to an other
> one, for example it can be used to 'convert' 'List[String] :: List[Int]' to
> 'Option[String] :: Option[Int]':
>
> Implemantation available here:
> https://github.com/aloiscochard/shapeless/commit/fe6932d3a813bbb9dd149218bbe345e892863a61
>
> By using 'Id' it's too possible to 'extract' type from a type constructor,
> please looks at test for more details.
>
> Don't hesitate to propose a better name!

I'm not so sure about this one. It seems like it's doing two things
simultaneously. First it's a constraint that all the elements of HList
L share the outer type constructor F[_]; and second it's computing the
result type of mapping a natural transformation F ~> G over L.

I'm not convinced that we need both of these combined into a single
type. Can't you just use the UnaryTCConstraint for the first part of,
and a Mapper/MapperAux for the second? Especially seeing as if you
need the type of the mapped result it's probably because you're going
to want to compute the map, so you'll need the Mapper/MapperAux
anyway?

Cheers,


Miles

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

Alois Cochard

unread,
Aug 4, 2012, 6:06:29 AM8/4/12
to shapel...@googlegroups.com
Hi Miles,

I got your point but I still think it's usefull,

In my use-case I don't want to compute the map, I just want to be able to receive a second HList with same inner type and different TC as expressed here:

Let's take for example siona-data, my NoSQL DSL, I want to be able, given a list of field to accept values for this fields.

An other example would be a web routing DSL (a la BigTop), where I receive a URL path containing parameters, and I want to accept a function accepting theses parameters.

What you think?

Cheers
Reply all
Reply to author
Forward
0 new messages