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
{-# LANGUAGE TypeFamilies | |
, DataKinds | |
, PolyKinds | |
, TypeInType | |
, TypeOperators | |
, UndecidableInstances | |
, RankNTypes | |
#-} | |
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
data Point = Pt Int Int | |
data Expr a = Number Integer | Boolean Bool |
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
# Problem Statement | |
# cons(a, b) constructs a pair, and car(pair) and cdr(pair) returns the first and last element of that pair. | |
# For example, car(cons(3, 4)) returns 3, and cdr(cons(3, 4)) returns 4. | |
# Given the below implementation for cons( ), please implement car & cdr | |
def cons(a, b): | |
def pair(f): | |
return f(a, b) | |
return pair |
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
trait Summable { | |
fn zero() -> Self; | |
fn add(&self, other: &Self) -> Self; | |
} | |
impl Summable for i32 { | |
fn zero() -> Self { | |
0 | |
} | |
fn add(&self, other: &Self) -> Self { |
OlderNewer