Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Liberate cosas from the unnecessary dependencies #48

Merged
merged 4 commits into from
Aug 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# http://www.scala-sbt.org/0.13/docs/Travis-CI-with-sbt.html
language: scala
scala:
- 2.11.4
- 2.10.4
- 2.11.7
- 2.10.5
jdk:
- oraclejdk8
- oraclejdk7
script: sbt ++$TRAVIS_SCALA_VERSION compile test package
script:
- sbt ++$TRAVIS_SCALA_VERSION compile test
# Tricks to avoid unnecessary cache updates
- find $HOME/.sbt -name "*.lock" | xargs rm
- find $HOME/.ivy2 -name "ivydata-*.properties" | xargs rm
matrix:
fast_finish: true
allow_failures:
- jdk: oraclejdk7
- scala: 2.10.5
notifications:
email: false
webhooks:
Expand All @@ -18,3 +22,10 @@ notifications:
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: false
# Use container-based infrastructure
sudo: false
# These directories are cached to S3 at the end of the build
cache:
directories:
- $HOME/.ivy2/cache
- $HOME/.sbt/boot/
8 changes: 3 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ organization := "ohnosequences"

bucketSuffix := "era7.com"

scalaVersion := "2.11.5"
scalaVersion := "2.11.7"

crossScalaVersions := Seq("2.10.4")
crossScalaVersions := Seq("2.10.5")

libraryDependencies += {
CrossVersion.partialVersion(scalaVersion.value) match {
Expand All @@ -21,9 +21,7 @@ libraryDependencies += {
}

libraryDependencies ++= Seq (
"org.scalaz" %% "scalaz-core" % "7.1.0",
"org.spire-math" %% "spire" % "0.9.0",
"org.scalatest" %% "scalatest" % "2.2.2" % Test
"org.scalatest" %% "scalatest" % "2.2.5" % Test
)

// wartremoverWarnings ++= Warts.all
Expand Down
67 changes: 40 additions & 27 deletions src/main/scala/cosas/ops/typeSets/Conversions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object ToHList {
def apply[S <: AnyTypeSet](implicit toHList: ToHList[S]): ToHList[S] = toHList

implicit def any[S <: AnyTypeSet, O <: HList]
(implicit
(implicit
mapper: MapToHList[id.type, S] { type Out = O }
): ToHList[S] with Out[O] =
new ToHList[S] with Out[O] {
Expand All @@ -33,17 +33,17 @@ object FromHList {

def apply[L <: HList](implicit fromHList: FromHList[L]): FromHList[L] = fromHList

implicit def hnil[N <: HNil]:
FromHList[N] with Out[∅] =
implicit def hnil[N <: HNil]:
FromHList[N] with Out[∅] =
new FromHList[N] with Out[∅] {
def apply(l: N): Out = ∅
}

implicit def cons[H, T <: HList, OutT <: AnyTypeSet]
(implicit
(implicit
rest: FromHList[T] { type Out = OutT },
check: H ∉ OutT
): FromHList[H :: T] with Out[H :~: OutT] =
): FromHList[H :: T] with Out[H :~: OutT] =
new FromHList[H :: T] with Out[H :~: OutT] {
def apply(l: H :: T): Out = l.head :~: rest(l.tail)
}
Expand All @@ -59,24 +59,24 @@ object ToList {
def apply[S <: AnyTypeSet](implicit toList: ToList[S]): ToList[S] = toList

// case object id_ extends Poly1 { implicit def default[T <: X, X] = at[T]{ (t: T) => (t: X) } }
// implicit def any[S <: AnyTypeSet, O](implicit

// implicit def any[S <: AnyTypeSet, O](implicit
// mapper: (id_.type MapToList S) with wrapped[O]
// ): ToList[S] with InContainer[O] =
// new ToList[S] with InContainer[O] { def apply(s: S): Out = mapper(s) }

implicit def empty[X]:
ToList[∅] with InContainer[X] =
implicit def empty[X]:
ToList[∅] with InContainer[X] =
new ToList[∅] with InContainer[X] { def apply(s: ∅): Out = Nil }

implicit def one[X, H <: X]:
ToList[H :~: ∅] with InContainer[X] =
new ToList[H :~: ∅] with InContainer[X] { def apply(s: H :~: ∅): Out = List[X](s.head) }

implicit def cons2[X, H1 <: X, H2 <: X, T <: AnyTypeSet]
(implicit
(implicit
lt: ToList[H2 :~: T] { type O = X }
): ToList[H1 :~: H2 :~: T] with InContainer[X] =
): ToList[H1 :~: H2 :~: T] with InContainer[X] =
new ToList[H1 :~: H2 :~: T] with InContainer[X] {

def apply(s: H1 :~: H2 :~: T): Out = s.head :: lt(s.tail.head :~: s.tail.tail)
Expand All @@ -94,8 +94,8 @@ object ParseFrom {
def apply[S <: AnyTypeSet, X]
(implicit parser: ParseFrom[S, X]): ParseFrom[S, X] = parser

implicit def empty[X]:
(∅ ParseFrom X) with Out[∅] =
implicit def empty[X]:
(∅ ParseFrom X) with Out[∅] =
new (∅ ParseFrom X) with Out[∅] {

def apply(s: ∅, x: X): Out = ∅
Expand All @@ -117,16 +117,6 @@ object ParseFrom {
}


// trait AnyMonoid {
// type M
// def zero: M
// def append(a: M, b: M): M
// }

// trait Monoid[T] extends AnyMonoid { type M = T }

import spire.algebra.Monoid

@annotation.implicitNotFound(msg = "Can't serialize typeset ${S} to ${X}")
trait SerializeTo[S <: AnyTypeSet, X] extends Fn1[S] with Out[X]

Expand All @@ -136,7 +126,7 @@ object SerializeTo {
(implicit serializer: S SerializeTo X): S SerializeTo X = serializer

implicit def empty[X](implicit m: Monoid[X]):
(∅ SerializeTo X) =
(∅ SerializeTo X) =
new (∅ SerializeTo X) {

def apply(r: ∅): Out = m.id
Expand All @@ -150,8 +140,31 @@ object SerializeTo {
t: T SerializeTo X
): ((H :~: T) SerializeTo X) =
new ((H :~: T) SerializeTo X) {

def apply(s: H :~: T): Out = m.op(f(s.head), t(s.tail))
}

}

trait AnyMonoid {
type M
def id: M
def op(a: M, b: M): M
}

trait Monoid[T] extends AnyMonoid { type M = T }

object AnyMonoid {

implicit def mapMonoid[X, Y]: Monoid[Map[X, Y]] = new Monoid[Map[X, Y]] {

def id: M = Map[X, Y]()
def op(a: M, b: M): M = a ++ b
}

implicit def listMonoid[X]: Monoid[List[X]] = new Monoid[List[X]] {

def id: M = List[X]()
def op(a: M, b: M): M = a ++ b
}
}
29 changes: 15 additions & 14 deletions src/test/scala/cosas/DenotationTests.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package ohnosequences.cosas.tests

import ohnosequences.cosas._, types._, AnySubsetType._
import ohnosequences.cosas.tests.asserts._

object DenotationTestsContext {

case object Color extends Wrap[String]("Color")
object User extends Type("User")
type User = User.type
object Friend extends Type("Friend")
case class userInfo(id: String, name: String, age: Int)
case class userInfo(id: String, name: String, age: Int)
}

class DenotationTests extends org.scalatest.FunSuite with ScalazEquality {
class DenotationTests extends org.scalatest.FunSuite {

import DenotationTestsContext._

Expand All @@ -23,10 +24,10 @@ class DenotationTests extends org.scalatest.FunSuite with ScalazEquality {

val x1 = "yellow" =: Color

assert{ azul.value == "blue" }
assert{ verde.value == "green" }
assert{ amarillo.value == "yellow" }
assert{ amarillo == x1 }
assert(azul.value == "blue")
assert(verde.value == "green")
assert(amarillo.value == "yellow")
assertTaggedEq(amarillo, x1)
}

test("create denotations") {
Expand All @@ -52,20 +53,20 @@ class DenotationTests extends org.scalatest.FunSuite with ScalazEquality {
val u2 = paco =: Friend
val v = jose =: Friend

assert { u1 == u1 }
assert { u1 == u1Again }
// assert { u2 =/= v } // not there in ScalaTest :-/
// assert { u1 === u2 }
assertTypeError("u1 === u2")
assert{ !( u2 == v ) }
assertTaggedEq(u1, u1)
assertTaggedEq(u1, u1Again)
// assertTaggedEq { u2, v } // not there in ScalaTest :-/
// assertTaggedEq { u1, u2 }
assertTypeError("u1 =~= u2")
assert{ !(v =~= u2) }
}

test("Denotation show") {

assert { (User := "hola").show == "(User := hola)" }
assert{ (User := "hola").show == "(User := hola)" }

val azul = Color := "blue"

assert(azul.show == "(Color := blue)")
assert{ azul.show == "(Color := blue)" }
}
}
17 changes: 0 additions & 17 deletions src/test/scala/cosas/RecordTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,7 @@ class RecordTests extends org.scalatest.FunSuite {

test("serialize") {

import spire.algebra.Monoid
// Map //
implicit def anyMapMonoid[X, Y]: Monoid[Map[X, Y]] = new Monoid[Map[X, Y]] {

type M = Map[X,Y]

def id: M = Map[X, Y]()
def op(a: M, b: M): M = a ++ b
}

implicit def serializeProperty[P <: AnyProperty](t: ValueOf[P])
(implicit p: P): Map[String, String] = Map(p.label -> t.value.toString)

Expand All @@ -255,14 +246,6 @@ class RecordTests extends org.scalatest.FunSuite {
)

// List //
implicit def anyListMonoid[X]: Monoid[List[X]] = new Monoid[List[X]] {

type M = List[X]

def id: M = List[X]()
def op(a: M, b: M): M = a ++ b
}

implicit def propertyIntToStr[P <: AnyProperty](t: ValueOf[P])
(implicit p: P): List[String] = List(t.show(p))

Expand Down
32 changes: 0 additions & 32 deletions src/test/scala/cosas/ScalazEquality.scala

This file was deleted.

5 changes: 3 additions & 2 deletions src/test/scala/cosas/SubsetTypesTests.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ohnosequences.cosas.tests

import ohnosequences.cosas._, types._, AnySubsetType._
import ohnosequences.cosas.tests.asserts._

object nelists {

Expand Down Expand Up @@ -29,7 +30,7 @@ object nelists {
}


class SubsetTypesTests extends org.scalatest.FunSuite with ScalazEquality {
class SubsetTypesTests extends org.scalatest.FunSuite {

test("naive nonempty lists") {

Expand All @@ -43,4 +44,4 @@ class SubsetTypesTests extends org.scalatest.FunSuite with ScalazEquality {

val u1: ValueOf[NEList[Int]] = 23 :: nelint
}
}
}
Loading