Skip to content

Instantly share code, notes, and snippets.

@mpilquist
Created May 15, 2013 16:06
Show Gist options
  • Save mpilquist/5585133 to your computer and use it in GitHub Desktop.
Save mpilquist/5585133 to your computer and use it in GitHub Desktop.
Example of using tagged boolean types in Scalaz 7
import scalaz.std.option._ // Import the some and none functions
import scalaz.syntax.std.option._ // Import the syntax for calling ~ on Option
import scalaz.std.AllInstances._ // Import all typeclass instances for standard datatypes
~some(10) // 10
~none[Int] // 0
~some("test") // "test"
~none[String] // ""
//~some(false) // could not find implicit value for parameter z: scalaz.Monoid[Boolean]
// There's no Monoid[Boolean] but there is a Monoid[Boolean @@ Tags.Conjunction] and a Monoid[Boolean @@ Tags.Disjunction]
import scalaz.{@@, Tags}
~some(Tags.Conjunction(true)) // true
~none[Boolean @@ Tags.Conjunction] // true
~some(Tags.Disjunction(true)) // true
~none[Boolean @@ Tags.Disjunction] // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment