Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
<:< versus HKT
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alan Burlison  
View profile  
 More options Sep 18 2012, 4:59 am
From: Alan Burlison <alan.burli...@gmail.com>
Date: Tue, 18 Sep 2012 09:59:54 +0100
Local: Tues, Sep 18 2012 4:59 am
Subject: <:< versus HKT
In "Scala in Depth" there is an example of the use of :<: to reify type
constraints:

def peek[C, A](col: C)(implicit ev: V <:< Traversable[A]) = (col.head, col)

the following version of peek also works, and (to me at least) seems
simpler as it doesn't require the use of an implicit:

def peek[A, C[A] <: Traversable[A]](col: C[A]) = (col.head, col)

What I'm not clear about is when you'd use one form over the other.  My
natural inclination would be to use the second exclusively, but I'm
pretty sure I'm missing something.

--
Alan Burlison
--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ken Scambler  
View profile  
 More options Sep 18 2012, 5:11 am
From: Ken Scambler <ken.scamb...@gmail.com>
Date: Tue, 18 Sep 2012 17:11:02 +0800
Local: Tues, Sep 18 2012 5:11 am
Subject: Re: [scala-user] <:< versus HKT

> What I'm not clear about is when you'd use one form over the other.  My
> natural inclination would be to use the second exclusively, but I'm pretty
> sure I'm missing something.

> --
> Alan Burlison
> --

Seth Tisue and I had an exchange on Scala Language the other day which
should fill in the gaps:

https://groups.google.com/forum/?fromgroups=#!topic/scala-language/ZA...

Basically, use <: when you can, and <:< when you must.

Cheers,
Ken


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josh Suereth  
View profile  
 More options Sep 18 2012, 7:17 am
From: Josh Suereth <joshua.suer...@gmail.com>
Date: Tue, 18 Sep 2012 07:17:00 -0400
Subject: Re: [scala-user] <:< versus HKT

That's a great motto.  <:< can help you bridge a type inference issue.   <:
should be preferred.

The Traversable example is, I believe, fixed in 2.10.
On Sep 18, 2012 5:11 AM, "Ken Scambler" <ken.scamb...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alan Burlison  
View profile  
 More options Sep 18 2012, 2:08 pm
From: Alan Burlison <alan.burli...@gmail.com>
Date: Tue, 18 Sep 2012 19:08:29 +0100
Local: Tues, Sep 18 2012 2:08 pm
Subject: Re: [scala-user] <:< versus HKT
On 18/09/2012 10:11, Ken Scambler wrote:

> Seth Tisue and I had an exchange on Scala Language the other day which
> should fill in the gaps:

> https://groups.google.com/forum/?fromgroups=#!topic/scala-language/ZA...

Thanks, I found the links you posted at the end of that thread very
interesting, especially the "Scala - a roadmap" thread.

--
Alan Burlison
--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
missingfaktor  
View profile  
 More options Sep 19 2012, 8:11 am
From: missingfaktor <rahul.phulore....@gmail.com>
Date: Wed, 19 Sep 2012 17:40:59 +0530
Local: Wed, Sep 19 2012 8:10 am
Subject: Re: [scala-user] <:< versus HKT

This thread might help too.
https://groups.google.com/forum/#!topic/scala-user/s38hv6culCw

On Tue, Sep 18, 2012 at 11:38 PM, Alan Burlison <alan.burli...@gmail.com>wrote:

--
Cheers,
Rahul.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alan Burlison  
View profile  
 More options Sep 19 2012, 11:09 am
From: Alan Burlison <alan.burli...@gmail.com>
Date: Wed, 19 Sep 2012 16:08:54 +0100
Local: Wed, Sep 19 2012 11:08 am
Subject: Re: [scala-user] <:< versus HKT
On 19/09/2012 13:10, missingfaktor wrote:

A bit.  I'm still not 100% clear when you *must* use implicit evidence
parameters because nothing else will work.  For example, in the toMap
example, if you need the supplied list to consist of 2-tuples, why can't
you just say that directly using the Tuple2 type?

In the example you give in the thread
(https://groups.google.com/d/msg/scala-user/s38hv6culCw/ssVM5X0ewbMJ) I
can see that you are using 'implicit ev: A =:= Int' to in effect defer
the check that A is an Int until that method is actually used.

However, I'm not clear in the toMap case why implicit evidence
parameters are necessary and a use of Tuple2 won't work, although I'm
struggling to come up with something that the Scala compiler actually likes.

Thanks for the link though, it did help some :-)

--
Alan Burlison
--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
missingfaktor  
View profile  
 More options Sep 19 2012, 3:07 pm
From: missingfaktor <rahul.phulore....@gmail.com>
Date: Thu, 20 Sep 2012 00:37:35 +0530
Local: Wed, Sep 19 2012 3:07 pm
Subject: Re: [scala-user] <:< versus HKT

Actually your hunch is right and there is a way to do that but I am not
sure I like it better than implicit parameters.

scala> :paste
// Entering paste mode (ctrl-D to finish)

class Lest[A](xs: List[A]) {
  def toMap[B, C, Dummy >: A <: (B, C)] : Map[B, C] = {
    Map.empty[B, C] ++ (xs : List[Dummy])
  }

}

val l = new Lest(List((3, 4), (1, 9)))
l.toMap[Int, Int, (Int, Int)]

// Exiting paste mode, now interpreting.

defined class Lest
l: Lest[(Int, Int)] = Lest@152b4053
res14: Map[Int,Int] = Map(3 -> 4, 1 -> 9)

On Wed, Sep 19, 2012 at 8:38 PM, Alan Burlison <alan.burli...@gmail.com>wrote:

--
Cheers,
Rahul.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
missingfaktor  
View profile  
 More options Sep 19 2012, 3:09 pm
From: missingfaktor <rahul.phulore....@gmail.com>
Date: Thu, 20 Sep 2012 00:38:59 +0530
Local: Wed, Sep 19 2012 3:08 pm
Subject: Re: [scala-user] <:< versus HKT

Also in this particular case, compiler cannot infer types with this scheme.

On Thu, Sep 20, 2012 at 12:37 AM, missingfaktor <rahul.phulore....@gmail.com

--
Cheers,
Rahul.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alan Burlison  
View profile  
 More options Sep 20 2012, 10:08 am
From: Alan Burlison <alan.burli...@gmail.com>
Date: Thu, 20 Sep 2012 15:07:53 +0100
Local: Thurs, Sep 20 2012 10:07 am
Subject: Re: [scala-user] <:< versus HKT
On 19/09/2012 20:07, missingfaktor wrote:

> Actually your hunch is right and there is a way to do that but I am not
> sure I like it better than implicit parameters.

> scala>  :paste
> // Entering paste mode (ctrl-D to finish)

> class Lest[A](xs: List[A]) {
>    def toMap[B, C, Dummy>: A<: (B, C)] : Map[B, C] = {
>      Map.empty[B, C] ++ (xs : List[Dummy])
>    }
> }

That's horrendously beautiful, or ugly, or just plain deranged, or
something...

I've tried to think of a way of avoiding the use of Dummy but can't
think of one.

Wow, my head is still spinning.  Thanks ;-)

--
Alan Burlison
--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »