Created
February 1, 2018 09:05
-
-
Save ismagin/97e47432416f971a05fee09aafcba3fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ex | |
import scodec.{Codec, codecs} | |
import scodec.codecs.{Discriminated, uint8} | |
object ASD extends App { | |
sealed trait Expr | |
case class INT(i: Int) extends Expr | |
case class SUM(i1: Expr, i2: Expr) extends Expr | |
import codecs.implicits._ | |
implicit def d = Discriminated[Expr, Int](uint8) | |
implicit def dInt = d.bind[INT](0) | |
implicit def dSum = d.bind[SUM](1) | |
val codec = Codec[Expr] | |
val term = (1 to 100000).foldLeft[Expr](INT(0))((acc, _) => SUM(acc, INT(1))) | |
codec.encode(term) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment