- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
whither newtype?
Thu, 2012-01-19, 00:51
#2
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.
Thu, 2012-01-19, 13:51
#3
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:
--
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
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
Thu, 2012-01-19, 14:41
#4
Re: whither newtype?
body p { margin-bottom: 0cm; margin-top: 0pt; }
Matthew Pocock wrote:
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
Thu, 2012-01-19, 14:51
#5
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.
Fri, 2012-01-20, 02:11
#6
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?
Fri, 2012-01-20, 19:21
#7
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.
On 19 January 2012 06:35, Raoul Duke <raould@gmail.com> wrote:
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