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
main = undefined | |
getAllSums x = [(l,r)| l <- partial_nat, r <- partial_nat, l + r == x ] | |
where partial_nat = [1..x] |
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
use std::string::String; | |
trait MyToStr { | |
fn my_to_str(s: &Self) -> String; | |
} | |
struct Foo { | |
name : String | |
} | |
impl MyToStr for Foo { | |
fn my_to_str(s : &Foo) -> String { |
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
fn compose<A, B, C>(f : |B| -> C, | |
g : |A| -> B) | |
-> |A| -> C{ | |
|x| f(g(x)) | |
} | |
fn main(){ | |
} |
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 Functor<A>{ | |
fn fmap<B>(f : |A| -> B, v : A) -> B; | |
} | |
impl Functor<i32> for i32 { | |
fn fmap<B>(f : |i32| -> B, v : i32) -> B { | |
f(v) | |
} | |
} | |
fn main(){ |
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 Functor<A,B,C>{ | |
fn fmap(&self, f : |&A| -> B) -> C; | |
} | |
impl<B> Functor<i32,B,B> for i32 { | |
fn fmap(&self,f : |&i32| -> B) -> B { | |
f(self) | |
} | |
} | |
impl<A,B> Functor<A,B,Vec<B>> for Vec<A> { | |
fn fmap(&self, f : |&A| -> B) -> Vec<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
# Define a daysBetweenDates procedure that would produce the | |
# correct output if there was a correct nextDay procedure. | |
# | |
# Note that this will NOT produce correct ouptuts yet, since | |
# our nextDay procedure assumes all months have 30 days | |
# (hence a year is 360 days, instead of 365). | |
# | |
def nextDay(year, month, day): | |
"""Simple version: assume every month has 30 days""" |
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
def nextDay(year, month, day): | |
"""Simple version: assume every month has 30 days""" | |
if day < 30: | |
return year, month, day + 1 | |
else: | |
if month == 12: | |
return year + 1, 1, 1 | |
else: | |
return year, month + 1, 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
#include <functional> | |
#include <iostream> | |
template<typename T> | |
class MaybePtr{ | |
T* ptr; | |
public: | |
MaybePtr(T* p) : ptr(p) {} | |
template <typename F,typename R = std::result_of<F(T*)>::type> | |
R Get(F access,R default_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
struct Foo{ | |
value: i32 | |
} | |
impl Foo{ | |
fn get_and_change_value(&mut self) -> i32{ | |
let v = self.value; | |
self.value = 42; | |
v | |
} | |
} |
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
#![feature(macro_rules)] | |
use std::comm; | |
macro_rules! with{ | |
($x:[expr]) =>{ | |
$x.i | |
} | |
} | |
trait ReactiveContainer<T> { | |
fn set_value(&mut self,value : T); |
OlderNewer