On 21 February 2014 21:35, Cédric Beust ♔ <[email protected]> wrote:

>
> On Fri, Feb 21, 2014 at 1:08 PM, Kevin Wright <[email protected]>wrote:
>
>> Sure, HLists handle this with aplomb:
>>
>> val xs = 1 :: 'a' :: 3.0f :: "hello world" :: HNil
>>
>>
>>
>> And this isn't just a "List of Int | Char | Float | String", it's a "List
>> of Int *then* Char *then* Float *then* String".
>>
>
> That's something I definitely want for tuples but probably not for lists,
> although there's definitely a bit of room for interpretation, here (the
> regular interpretation for a list expects the ordering to be preserved but
> if you look at List from the monad perspective, a list is just an
> enumeration of multiple outcomes, and the ordering is meaningless).
>

Not so!  A list has a very definite concept of maintaining its sequence;
it's Set that doesn't.

Shapeless can quite happily translate between HLists and Tuples (and case
classes) and will even retrofit HList behaviour onto Tuples.
This means you can do a lot of stuff not typically associated with Tuples:
zipping, concatenation, splitting, partitioning, mapping, flatMapping,
reversing, head, tail, etc.

Note that you can write code with HLists that abstracts over the length -
which isn't so easy with Tuples :)



> Also, the fact that Shapeless does it this way is not really a voluntary
> design choice: the inferrer has simply no choice in the matter, so it's
> more of a restriction of Scala's type system than anything else (another
> reason why I say that not having union/intersection types baked into the
> type system imposes a lot of limitations).
>

Absolutely it's a limitation, hence the need for Coproducts and Dotty.  I
wouldn't say that HLists are a workaround for the lack of built-in
intersection though, they're a very different tools that can sometimes be
used in the same way.


>
> --
> Cédric
>
>

-- 
You received this message because you are subscribed to the Google Groups "Java 
Posse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/javaposse.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to