Skip to content

Instantly share code, notes, and snippets.

View JoeyEremondi's full-sized avatar

Joey Eremondi JoeyEremondi

View GitHub Profile
use std::boxed::Box;
use std::rc::Rc;
use std::borrow::Borrow;
use std::mem;
struct BP_Borrow;
struct BP_RC;
trait BorrowPlus<Borrowed, TRef> : Borrow<Borrowed>
use std::boxed::Box;
use std::borrow::Borrow;
#[derive(Debug)]
enum List<T> {
Null,
Cons(T, Box<List<T>>),
}
fn map<A, B, F: Fn(&A) -> B, L: Borrow<List<A>>>(f: F, lst: L) -> List<B> {
use std::boxed::Box;
enum List<T> {
Null,
Cons(T, Box<List<T>>),
}
fn map_noref<A, B, F>(f: &F, lst: List<A>) -> List<B>
where F: Fn(A) -> B
use std::rc::Rc;
enum List<T> {
Null,
Cons(Rc<T>, Rc<List<T>>),
}
fn map_noref<A, B, F>(f: &F, lst: Rc<List<A>>) -> Rc<List<B>>
where F: Fn(Rc<A>) -> Rc<B>
use std::rc::Rc;
enum List<T> {
Null,
Cons(Rc<T>, Rc<List<T>>),
}
-- Given these simplified types:
data Model = Model { something :: SomeSubData }
data SomeSubData = SomeSubData { moreThing :: Integer }
-- And given this value
where
model = Model (SomeSubData 42)
maxNum : List ( comparable, number ) -> Maybe ( comparable, number )
maxNum tuples =
case tuples of
x :: xs ->
Just
(List.foldl
(\(( _, count ) as tup) maxSoFar ->
if count > (snd maxSoFar) then
tup
else
import Color exposing (..)
import Graphics.Element exposing (show)
d x = x
f x = x
labToColor : { l : Float, a : Float, b : Float } -> Color
labToColor { l, a, b } =
let
-- interface is a more familiar name for the intention of the construct
type alias Append a rest = { rest | append : a -> a -> a}
-- implement is a more familiar name
stringAppend rest = {rest | append = \x y -> x ++ y}
-- this is Monoid
type alias AppendWithId a rest = Append a {rest | id : a}
-- ^ 1 potential superclass
module Dict
( Dict
, empty, singleton, insert, update
, isEmpty, get, remove, member, size
, filter
, partition
, foldl, foldr, map
, union, intersect, diff
, keys, values
, toList, fromList