Skip to content

Instantly share code, notes, and snippets.

@milessabin
Created February 6, 2013 02:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save milessabin/4719811 to your computer and use it in GitHub Desktop.
Save milessabin/4719811 to your computer and use it in GitHub Desktop.
Sneak preview for NEScala
scala> def foo[A, B, C](a: SNat[A], b: SNat[B], c: SNat[C])(implicit ssum: SSum[A, B, C]) = ssum
foo: [A, B, C](a: shapeless.SNat[A], b: shapeless.SNat[B], c: shapeless.SNat[C])(implicit ssum: shapeless.SSum[A,B,C])shapeless.SSum[A,B,C]
scala> foo(2, 3, 5)
res0: shapeless.SSum[Int(2),Int(3),Int(5)] = $anon$1@53d76e96
scala> foo(2, 3, 7)
<console>:15: error: could not find implicit value for parameter ssum: shapeless.SSum[Int(2),Int(3),Int(7)]
foo(2, 3, 7)
^
@julienrf
Copy link

julienrf commented Feb 6, 2013

Fun :)
Why not add the following syntactic sugar?

type Args = { type Lhs; type Rhs }
type +[A, B] = Args { type Lhs = A; type Rhs = B }
type ==[A <: Args, B] = SSum[A#Lhs, A#Rhs, B]

def foo[A, B, C](a: SNat[A], b: SNat[B], c: SNat[C])(implicit ev: A + B == C) = ev

@hedefalk
Copy link

hedefalk commented Feb 6, 2013

Man, you're beating that compiler bloody! Soon I'll ditch my old prolog code and just use scalac. I'll even leave the runtime at home.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment