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
package control | |
trait Applicative[M[_]] extends Functor[M] { | |
def pure[A](a: A): M[A] | |
def applicative[A, B](f: M[A => B])(a: M[A]): M[B] | |
override def map[A, B](f: A => B)(a: M[A]): M[B] = applicative(pure(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
#![allow(dead_code)] | |
use std::io::{self, Read}; | |
use std::marker::PhantomData; | |
pub trait Foo<T: Read> { | |
fn get_mut(&self) -> &mut T; | |
} | |
struct FooStruct<T,R> where T:Read, R:Foo<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
#![allow(dead_code)] | |
use std::marker::PhantomData; | |
// ----------------------------------------------------------------------------- | |
// Response definition | |
// ----------------------------------------------------------------------------- | |
pub enum Response<A> { | |
Success(A, usize), |
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
#[macro_export] | |
macro_rules! foreach { | |
($a:ident <- ($e:expr) if ($cond:expr) yield $result:expr) => {{ | |
$e.filter(|$a| $cond).map(|$a| $result) | |
}}; | |
($a:ident <- ($e:expr) yield $result:expr) => {{ | |
$e.map(|$a| $result) | |
}}; | |
($a:ident <- ($e:expr) $($r:tt)+) => {{ | |
$e.flat_map(|$a| foreach!($($r)+)) |
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
#[macro_export] | |
macro_rules! comprehension { | |
(($expr:expr) | $id:ident <- ($range:expr) if $cond:expr) => {{ | |
let mut result = Vec::default(); | |
for $id in $range { | |
if $cond { | |
result.push($expr); | |
} | |
} |
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
//--------------------------------------------------------------------------------- | |
// Parser trait type defintion | |
//--------------------------------------------------------------------------------- | |
trait Parser<E> {} | |
//--------------------------------------------------------------------------------- | |
// Executable Parsers (Self is constraint) | |
//--------------------------------------------------------------------------------- |
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
module TennisKata | |
%default total | |
-- Data types | |
data Point = Love | Fiftheen | Thirteen | Fourteen | |
isFourteen : Point -> Bool | |
isFourteen Fourteen = True |
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
protocol A { | |
associatedtype E | |
func new() -> E? | |
} | |
protocol C { | |
init() | |
} |
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 Foundation | |
public indirect enum Peano: ExpressibleByIntegerLiteral { | |
case Succ(Peano), | |
Zero | |
public init(integerLiteral v: IntegerLiteralType) { | |
if v == 0 { | |
self = .Zero | |
} else { |
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
// | |
// From https://www.parleys.com/tutorial/type-level-programming-scala-101 | |
// | |
import scala.language.higherKinds | |
// Int type programming level | |
sealed trait IntType { | |
type plus[that <: IntType] <: IntType |