Skip to content

Instantly share code, notes, and snippets.

// concepts:
// - functional style: higher-order functions, type aliases
// - testing in REPL
object AreaCalculatorApp {
def main(args: Array[String]) = println(area(readVertices(args(0))))
type Vertex = (Double, Double)
def area(vertices: Seq[Vertex]) = triangulate(vertices) map(triangleArea _) sum
// concepts:
// - actors
// - pattern matching
// - Option (None/Some(x))
// -- enums etc
object Figure extends Enumeration {
type Figure = Value
val Paper, Scissors, Stone = Value
}
@mmakowski
mmakowski / MVC.hs
Created March 2, 2011 09:41
Model-View-Controller in wxHaskell
{-
Haskell MVC
===========
with wxHaskell and STM
With popularity of Haskell raising in recent years I have decided to have a
look at how suitable it is as a general-purpose programming language. The
experiment involves writing a Windows client for FIBS
(https://github.com/mmakowski/habaz).
@mmakowski
mmakowski / Automata.hs
Created November 16, 2011 21:12 — forked from petermarks/Automata.hs
Automata
{- requires -XArrows -}
module Automata where
import Prelude hiding (id, (.))
import Control.Category
import Control.Arrow
import qualified Data.Map as M
import Data.List (sort)
data Automaton b c = Automaton (b -> (c, Automaton b c))
import Data.Enumerator hiding (map, length, foldl)
import qualified Data.Enumerator.Text as ET
import qualified Data.Enumerator.List as EL
import Data.List (sort)
import qualified Data.Map as M
import Data.Text (Text)
data Entry = Entry { date :: String
, host :: String
{-
One process starts the master process
Other start do-nothing process
master distributes the work among the other processes
-}
module Main where
import Remote
import Control.Monad
--------------------------------------------------------------------
-- |
-- Module : Text.JSON.Parsec
-- Copyright : (c) Galois, Inc. 2007-2009
--
-- Maintainer: Sigbjorn Finne <sof@galois.com>
-- Stability : provisional
-- Portability: portable
--
-- Parse JSON values using the Parsec combinators.
{-# LANGUAGE DeriveFunctor, DeriveFoldable, DeriveTraversable #-}
{-
tree they help
2854 8531 8422 2955
t= r= e= h= y= l= p=
-}
module Decode where
{-
@mmakowski
mmakowski / ch05-stream.scala
Created March 11, 2012 14:02
fp-in-scala: ch05-stream
trait Stream[A] {
def exists(f: A => Boolean): Boolean = foldRight(false)((h, t) => f(h) || t)
def foldRight[B](z: => B)(f: (A, => B) => B): B =
uncons map { case (h ,t) => f(h, t.foldRight(z)(f)) } getOrElse z
def forall(f: A => Boolean): Boolean = foldRight(true)((h, t) => f(h) && t)
def take(n: Int): Stream[A] =
if (n == 0) Stream.empty
module Puzzle where
import Data.List
data Girl = Ellie | Emily | Jessica deriving (Bounded, Enum, Eq, Show)
data Animal = Elephant | Zebra | Giraffe deriving (Bounded, Enum, Eq, Show)
data Lolly = Grunge | Plooper | Zinger deriving (Bounded, Enum, Eq, Show)
data Adult = Aunt | Grandma | Mum deriving (Bounded, Enum, Eq, Show)