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 ds.tree.aa | |
import scala.annotation.tailrec | |
// https://en.wikipedia.org/wiki/AA_tree | |
sealed trait Tree | |
final case class Node(var key: Int, var level: Int, var left: Tree, var right: Tree) extends Tree |
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
// Cargo.toml | |
// | |
// [dependencies] | |
// futures = "0.3.25" | |
use std::future::Future; | |
use std::ops::Deref; | |
use std::pin::Pin; | |
use std::sync::{Arc, Mutex}; | |
use std::sync::mpsc::{Receiver, sync_channel, SyncSender}; |
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 example | |
import java.util.UUID | |
import shapeless.labelled.FieldType | |
import shapeless.ops.hlist.MapFolder | |
import shapeless.{HList, LabelledGeneric, Poly1, Witness} | |
sealed trait Table extends Product { | |
type Id |
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 math | |
import cats.instances.list._ | |
import cats.syntax.all._ | |
import io.circe.generic.auto._ | |
import io.circe.parser._ | |
import scala.io.Source | |
/** |
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 example | |
import shapeless._ | |
import shapeless.labelled.FieldType | |
object LabelledDerivation extends App { | |
import JsonObjectEncoder._ | |
println { | |
JsonEncoder[IceCream].encode(IceCream("Sunday", 25)) |
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 example | |
import shapeless._ | |
object TypeclassDerivation extends App { | |
println { | |
CsvEncoder.writeCsv(IceCream("Sunday", 25)) | |
// "Sunday,25" | |
} |
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 demo | |
//talk: https://vimeo.com/28793245 | |
//Kind | |
class HOMap[K[_], V[_]](delegate: Map[K[Any], V[Any]]) { | |
def apply[A](key: K[A]): V[A] = | |
delegate(key.asInstanceOf[K[Any]]).asInstanceOf[V[A]] | |
} |
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
import Data.Vect | |
-- matrix representation using vectors | |
Matrix : (rows : Nat) -> (cols : Nat) -> (elem : Type) -> Type | |
Matrix rows cols elem = Vect rows (Vect cols elem) | |
-- add corresponding elements from two vectors | |
vector_op : Num elem => ((elem, elem) -> elem) -> Vect c elem -> Vect c elem -> Vect c elem | |
vector_op op av bv = let ts = zip av bv in map op ts |
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 lambdacalculus | |
/** | |
* Abstract Syntax (AST) for lambda terms | |
* | |
* In the simplest form of lambda calculus, terms are built using only the following rules: | |
* | |
* Variable (x) | |
* A character or string representing a parameter. | |
* Abstraction (λx.M) |
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
module AppendixA | |
// Programming Language Concepts by Peter Sestoft | |
// $ fsharpi | |
// > #load "AppendixA.fs";; | |
// > open AppendixA;; | |
// > let t = Br (1, Br (2, Lf, Lf), Br (3, Lf, Lf));; | |
// Exercise A.1 |
NewerOlder