This page is no longer maintained — Please continue to the home page at www.scala-lang.org

whither newtype?

7 replies
Raoul Duke
Joined: 2009-01-05,
User offline. Last seen 42 years 45 weeks ago.

anything newlyoflate succinctly like haskell-newtype? thanks.

Ken Scambler
Joined: 2009-11-07,
User offline. Last seen 42 years 45 weeks ago.
Re: whither newtype?


On 19 January 2012 06:35, Raoul Duke <raould@gmail.com> wrote:
anything newlyoflate succinctly like haskell-newtype? thanks.

I think the usual idiom is to just do something like case class Name(name: String), maybe adding implicit conversions to taste.  Also, Scalaz has a class explicitly for this purpose: http://scalaz.github.com/scalaz/scalaz-2.9.1-6.0.2/doc/scalaz/NewType.html

Ken
Raoul Duke
Joined: 2009-01-05,
User offline. Last seen 42 years 45 weeks ago.
Re: whither newtype?

On Wed, Jan 18, 2012 at 3:09 PM, Ken Scambler wrote:
> http://scalaz.github.com/scalaz/scalaz-2.9.1-6.0.2/doc/scalaz/NewType.html

w00t, thanks.

Matthew Pocock 3
Joined: 2010-07-30,
User offline. Last seen 42 years 45 weeks ago.
Re: whither newtype?
The point of newtype in haskell is that you get type-dependent dispatch without the overhead of run-time indirection. All the approaches I've found in scala result in a new object being generated that points to the thing you want to newtype. Perhaps there's a way.
Matthew

On 18 January 2012 23:41, Raoul Duke <raould@gmail.com> wrote:
On Wed, Jan 18, 2012 at 3:09 PM, Ken Scambler <ken.scambler@gmail.com> wrote:
> http://scalaz.github.com/scalaz/scalaz-2.9.1-6.0.2/doc/scalaz/NewType.html

w00t, thanks.



--
Dr Matthew PocockIntegrative Bioinformatics Group, School of Computing Science, Newcastle Universitymailto: turingatemyhamster@gmail.com gchat: turingatemyhamster@gmail.commsn: matthew_pocock@yahoo.co.uk irc.freenode.net: drdozerskype: matthew.pococktel: (0191) 2566550mob: +447535664143
Ittay Dror 2
Joined: 2010-05-05,
User offline. Last seen 42 years 45 weeks ago.
Re: whither newtype?
body p { margin-bottom: 0cm; margin-top: 0pt; }

Hmmm, I think Miles' unboxed newtype is what you're looking for: https://gist.github.com/89c9b47a91017973a35f

See here for usage: https://github.com/retronym/scalaz7-experimental/blob/master/core/src/main/scala/scalaz/std/AnyVal.scala

Ittay


Matthew Pocock wrote:
X0t4kA [at] mail [dot] gmail [dot] com" type="cite">The point of newtype in haskell is that you get type-dependent dispatch without the overhead of run-time indirection. All the approaches I've found in scala result in a new object being generated that points to the thing you want to newtype. Perhaps there's a way.
Matthew

On 18 January 2012 23:41, Raoul Duke <raould [at] gmail [dot] com" rel="nofollow">raould@gmail.com> wrote:
On Wed, Jan 18, 2012 at 3:09 PM, Ken Scambler <ken [dot] scambler [at] gmail [dot] com" rel="nofollow">ken.scambler@gmail.com> wrote:
> http://scalaz.github.com/scalaz/scalaz-2.9.1-6.0.2/doc/scalaz/NewType.html

w00t, thanks.



--
Dr Matthew Pocock Integrative Bioinformatics Group, School of Computing Science, Newcastle University mailto: turingatemyhamster [at] gmail [dot] com" target="_blank" rel="nofollow">turingatemyhamster@gmail.com gchat: turingatemyhamster [at] gmail [dot] com" target="_blank" rel="nofollow">turingatemyhamster@gmail.com msn: matthew_pocock [at] yahoo [dot] co [dot] uk" target="_blank" rel="nofollow">matthew_pocock@yahoo.co.uk irc.freenode.net: drdozer skype: matthew.pocock tel: (0191) 2566550 mob: +447535664143
Lars Hupel
Joined: 2010-06-23,
User offline. Last seen 44 weeks 3 days ago.
Re: whither newtype?

> The point of newtype in haskell is that you get type-dependent dispatch
> without the overhead of run-time indirection. All the approaches I've found
> in scala result in a new object being generated that points to the thing
> you want to newtype. Perhaps there's a way.

See unboxed tagged types.

Tony Morris 2
Joined: 2009-03-20,
User offline. Last seen 42 years 45 weeks ago.
Re: whither newtype?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 01/19/2012 05:35 AM, Raoul Duke wrote:
> anything newlyoflate succinctly like haskell-newtype? thanks.

What does newtype on its own provide? Not much, but a compiler
optimisation removing a pointer indirection.

However, newtype along with deriving (keyword) is a powerful beast --
one that scala could certainly benefit from. This would be a significant
language change, but it would also solve a lot of problems that pass
here on the mailing list.

Maybe you mean newtype with deriving?

Raoul Duke
Joined: 2009-01-05,
User offline. Last seen 42 years 45 weeks ago.
Re: whither newtype?

On Wed, Jan 18, 2012 at 12:51 PM, Tony Morris wrote:
> Maybe you mean newtype with deriving?

indeed maybe.

what i want is to be able to take something that already exists e.g.
Int (or is it Integer, i can never remember) and makes a new type e.g.
Inches that is basically an Int but they are not assignable w/out
explicit casts. a typedef but that is more strictly partitioning the
new type than typedef is in c.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland