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 Main extends App { | |
// Too busy helping people on Gitter and Reddit | |
} |
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 Main extends App { | |
def fix[A](f: (=> A) => A): A = { | |
lazy val a: A = f(a) | |
a | |
} | |
val gac: (=> BigInt => BigInt) => BigInt => BigInt = | |
fac => n => if (n == 0) 1 else n * fac.apply(n - 1) |
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 Main extends App { | |
trait Functor[F[_]] { | |
def map[A, B](fa: F[A])(f: A => B): F[B] | |
} | |
final case class Fix[F[_]](unfix: F[Fix[F]]) | |
final case class Cofree[F[_], A](head: A, tail: F[Cofree[F, A]]) | |
sealed trait Free[F[_], A] | |
final case class Continue[F[_], A](a: A) extends Free[F, A] |
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 Main extends App { | |
trait Functor[F[_]] { | |
def map[A, B](fa: F[A])(f: A => B): F[B] | |
} | |
sealed trait Nat[A] | |
final case class Z[A]() extends Nat[A] | |
final case class S[A](a: A) extends Nat[A] |
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 Main extends App { | |
import shapeless._ | |
import nat._ | |
import ops.nat._ | |
trait Factorial[I <: Nat] { type Out <: Nat } | |
object Factorial { | |
def factorial[N <: Nat](i: Nat)(implicit fact: Factorial.Aux[i.N, N], | |
wn: Witness.Aux[N]): N = wn.value |
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 Main extends App { | |
sealed trait Trampoline[+A] { | |
def map[B](f: A => B): Trampoline[B] = flatMap(f.andThen(Done(_))) | |
def flatMap[B](f: A => Trampoline[B]): Trampoline[B] = FlatMap(this, f) | |
} | |
final case class Done[A](a: A) extends Trampoline[A] | |
final case class More[A](resume: () => Trampoline[A]) extends Trampoline[A] | |
final case class FlatMap[A, B](sub: Trampoline[A], k: A => Trampoline[B]) |
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 Main extends App { | |
trait Nat { | |
type +[A <: Nat] <: Nat | |
type *[A <: Nat] <: Nat | |
type ! <: Nat | |
} | |
trait Z extends Nat { | |
type +[A <: Nat] = A |
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 java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.math.BigInteger; | |
public class Main { | |
public static void main(String[] args) { | |
System.out.print("Please enter a number: "); | |
InputStreamReader read = new InputStreamReader(System.in); | |
BufferedReader in = new BufferedReader(read); |
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 Main extends App { | |
sealed trait Nat | |
case object Z extends Nat | |
case class S(n: Nat) extends Nat | |
def natToInt(nat: Nat): Int = nat match { | |
case Z => 0 | |
case S(n) => 1 + natToInt(n) | |
} |
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 org.apache.spark.{SparkConf, SparkContext} | |
import scala.util.{Failure, Success, Try} | |
object Main extends App { | |
def createSparkContext: SparkContext = { | |
val conf = new SparkConf().setMaster("local[*]").setAppName("Factorial") | |
val sc = new SparkContext(conf) | |
sc.setLogLevel("ERROR") |
NewerOlder