Skip to content

Instantly share code, notes, and snippets.

View Jonplussed's full-sized avatar

Jonathan Childress Jonplussed

  • Portland, OR
View GitHub Profile
@Jonplussed
Jonplussed / LengthList.hs
Last active November 15, 2015 18:33 — forked from twopoint718/Lits.hs
Not quite sure how to implement
{-# LANGUAGE DataKinds
, GADTs
, KindSignatures
, ScopedTypeVariables
, TypeOperators
#-}
module LengthList
( LengthList (..)
-- examples
module DefArgs
( Vec4 (..)
, ToVec4
, toVec4
) where
data Vec4 = Vec4 Number Number Number Number
instance showVec4 :: Show Vec4 where
show (Vec4 x y z t) =
{-# LANGUAGE FlexibleInstances #-}
module DefaultArgs where
{-
Lots 'o languages give you functions with default arguments. For instance, in Ruby:
def foo(bar, baz=0, quux=1)
# stuff...
end
@Jonplussed
Jonplussed / monadic_builtins.rs
Last active August 29, 2015 14:06
Add applicative `fmap` and monadic `bind` to Rust's builtin enums
trait MonadicOpt<T> {
fn fmap<U>(self, f: |T| -> U) -> Option<U>;
fn bind<U>(self, f: |T| -> Option<U>) -> Option<U>;
}
impl<T> MonadicOpt<T> for Option<T> {
fn fmap<U>(self, f: |T| -> U) -> Option<U> {
match self {
Some(x) => Some(f(x)),
_ => None,