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
-- Inspired by http://www.csis.pace.edu/~bergin/patterns/ppoop.html | |
-- and by Rob Pike's response: https://plus.google.com/+RobPikeTheHuman/posts/hoJdanihKwb | |
import System.Info (os) | |
import Data.Map (Map, findWithDefault, fromList) | |
class AbstractOsObject a where | |
getOsString :: a -> String | |
coerce :: a -> BaseOsObject |
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
data List a = Empty | Cons a (List a) deriving (Eq, Read, Ord, Show) | |
instance Foldable List where | |
foldr _ acc Empty = acc | |
foldr f acc (Cons x xs) = f x (foldr f acc xs) | |
instance Functor List where | |
fmap f xs = foldr (\x acc -> Cons (f x) acc) Empty xs | |
instance Traversable List where |
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
type [a] = [] | a : [a] | |
instance Monad (a ↦ [a]) where | |
fmap ∷ (a → b) → List a → List b | |
fmap _ [] = [] | |
fmap f (x : xs) = (f x) : (fmap f xs) | |
pure ∷ a → List a | |
pure x = x : [] |
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
/* ES5-style class declaration */ | |
function ParsedTime(hour, minute, second) { | |
this.hour = hour | |
this.minute = minute | |
this.second = second | |
this.toString = function () { | |
return JSON.stringify(this) | |
} | |
} |
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
def fourier_series(n, samples): | |
""" | |
`fourier_series` | |
From a list of `samples` taken from an unknown periodic function, | |
returns the best-fit `n`-term sine/cosine approximation of the | |
unknown function. | |
Args: | |
param1 (int): The number of terms you want in your |
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
package local | |
import scalaz.Monoid._ | |
object ServerConfig { | |
case class Port(get: Int = 8080) | |
case class Zookeeper(get: String = "default_zookeeper") | |
case class Environemnt(get: String = "default_env") |
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
sealed trait Either[S, T] { | |
def fold[X]: (S => X) => (T => X) => X | |
def map[X]: (T => X) => Either[S, X] | |
def bind[X]: (T => Either[S, X]) => Either[S, X] | |
} | |
object Either { |
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
import System.Environment (getArgs) | |
main = getArgs >>= (putStrLn . triangle . read . head) | |
where | |
triangle n = unlines $ map mkline $ [1..n] | |
mkline i = unwords $ take i $ drop (i `mod` 2) $ altern | |
altern = "0" : "1" : altern |
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
import java.util.Optional; | |
import java.util.function.Function; | |
public abstract class Either<L, R> { | |
public static <L0, R0> Either<L0, R0> left(L0 value) { | |
return new Left<L0, R0>(value); | |
} | |
public static <L0, R0> Either<L0, R0> right(R0 value) { |
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
data Mat a = M !a !a !a !a deriving (Eq, Read, Show) | |
-- 2x2 matrix multiplication | |
matMult :: Num a => Mat a -> Mat a -> Mat a | |
matMult (M x11 x12 x21 x22) (M y11 y12 y21 y22) = M z11 z12 z21 z22 | |
where | |
z11 = x11*y11 + x12*y21 | |
z12 = x11*y12 + x12*y22 | |
z21 = x21*y11 + x22*y21 | |
z22 = x21*y12 + x22*y22 |
OlderNewer