Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

README.md

sing 0.2.0

sing is a type-level metaprogramming library for Scala. This is based upon the singleton type system emulation. "sing" represents "singleton" and "compile-time and runtime methods sing in chorus":

import com.github.okomok.sing._
import Dense._

class PrimesTest extends org.scalatest.junit.JUnit3Suite {

    final class Sieve extends AsFunction1 {
        override type self = Sieve
        override  def apply[ns <: Any](ns: ns): apply[ns] = ns.asList.tail.filter(NonDiv(ns.asList.head.asNat))
        override type apply[ns <: Any]                    = ns#asList#tail#filter[NonDiv[ns#asList#head#asNat]]
    }
    val Sieve: Sieve = new Sieve

    final case class NonDiv[n <: Nat](n: n) extends AsFunction1 {
        override type self = NonDiv[n]
        override  def apply[x <: Any](x: x): apply[x] = x.asNat.rem(n).nequal(_0)
        override type apply[x <: Any]                 = x#asNat#rem[n]#nequal[_0]
    }

    final class Head extends AsFunction1 {
        override type self = Head
        override  def apply[x <: Any](x: x): apply[x] = x.asList.head
        override type apply[x <: Any]                 = x#asList#head
    }
    val Head: Head = new Head

     val primes: primes = List.iterate( List.rangeFrom(_2), Sieve ).map(Head)
    type primes         = List.iterate[ List.rangeFrom[_2], Sieve ]#map[Head]

    def testMe {
         val some: some = primes.take(_10).force
        type some       = primes#take[_10]#force

        Test.assertSame(some, _2 :: _3 :: _5 :: _7 :: _11 :: _13 :: _17 :: _19 :: _23 :: _29 :: Nil)
        Test.assertSame[some, _2 :: _3 :: _5 :: _7 :: _11 :: _13 :: _17 :: _19 :: _23 :: _29 :: Nil]
    }
}

Links

Shunsuke Sogame <okomok@gmail.com>

About

Type-Level Metaprogramming Library in Scala

Resources

Languages

You can’t perform that action at this time.