This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Front-end Setup</title> | |
| </head> | |
| <body> | |
| <h2>Frontend Setup</h2> | |
| </body> | |
| </html> |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Front-end Setup</title> | |
| <link rel="stylesheet" href="../../static/lib/css/bootstrap.min.css"> | |
| </head> | |
| <body> | |
| <div class="container"> |
This file contains hidden or 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
| implicit def pairGroup[T1: Group, T2: Group]: Group[(T1, T2)] = { | |
| val t1Group = implicitly[Group[T1]] | |
| val t2Group = implicitly[Group[T2]] | |
| new Group[(T1, T2)] { | |
| val zero = (t1Group.zero, t2Group.zero) | |
| def plus(x: (T1, T2), y: (T1, T2)): (T1, T2) = (x, y) match { | |
| case ((x1, x2), (y1, y2)) => | |
| (t1Group.plus(x1, y1), t2Group.plus(x2, y2)) |
This file contains hidden or 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
| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
This file contains hidden or 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
| object GroupSyntax { | |
| implicit class GroupOps[T](val x: T) extends AnyVal { | |
| def |+|(y: T)(implicit ev: Group[T]): T = ev.plus(x, y) | |
| def inverse(implicit ev: Group[T]): T = ev.inverse(x) | |
| def |-|(y: T)(implicit ev: Group[T]): T = ev.minus(x, y) | |
| } | |
| def zero[T: Group]: T = Group[T].zero | |
| } |
This file contains hidden or 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
| implicit object DoubleGroup extends Group[Double] { | |
| val zero: Double = 0.0 | |
| def plus(x: Double, y: Double): Double = x + y | |
| def inverse(x: Double): Double = -x | |
| } |
This file contains hidden or 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
| object Group { | |
| def apply[T: Group]: Group[T] = implicitly[Group[T]] | |
| // Instances of Group[T]... | |
| } |
This file contains hidden or 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
| object Group extends TypeClassCompanion[Group] { | |
| // Instances ... | |
| } |
This file contains hidden or 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
| import annotation.implicitNotFound | |
| @implicitNotFound("No member of type class Group found for type ${T}") | |
| trait Group[T] { | |
| // code .. | |
| } |
This file contains hidden or 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
| // xs.foldLeft(z)(op) reduces to | |
| // (..(((z op x(0)) op x(1)) op x(2)) ... op x(n)) | |
| def sum(elems : Seq[Int]): Int = | |
| elems.foldLeft(0) { _ + _ } |