This file contains 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 DataKinds | |
, GADTs | |
, KindSignatures | |
, ScopedTypeVariables | |
, TypeOperators | |
#-} | |
module LengthList | |
( LengthList (..) | |
-- examples |
This file contains 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 DefArgs | |
( Vec4 (..) | |
, ToVec4 | |
, toVec4 | |
) where | |
data Vec4 = Vec4 Number Number Number Number | |
instance showVec4 :: Show Vec4 where | |
show (Vec4 x y z t) = |
This file contains 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 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 |
This file contains 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 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, |