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 main | |
import "fmt" | |
type Peano interface { isPeano() } | |
// Zero | |
type Zero struct {} | |
func (z Zero) isPeano() {} |
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
# | |
# Simpla and Naive type checker ... | |
# | |
import inspect | |
class TypeCheckError(Exception): | |
pass | |
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 |
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
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
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
//--------------------------------------------------------------------------------- | |
// 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
#[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
#[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
#![allow(dead_code)] | |
use std::marker::PhantomData; | |
// ----------------------------------------------------------------------------- | |
// Response definition | |
// ----------------------------------------------------------------------------- | |
pub enum Response<A> { | |
Success(A, usize), |
OlderNewer