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
// 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 |
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
// concepts: | |
// - actors | |
// - pattern matching | |
// - Option (None/Some(x)) | |
// -- enums etc | |
object Figure extends Enumeration { | |
type Figure = Value | |
val Paper, Scissors, Stone = 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
{- | |
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). |
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
{- 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)) |
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 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 |
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
{- | |
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 |
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 : Text.JSON.Parsec | |
-- Copyright : (c) Galois, Inc. 2007-2009 | |
-- | |
-- Maintainer: Sigbjorn Finne <[email protected]> | |
-- Stability : provisional | |
-- Portability: portable | |
-- | |
-- Parse JSON values using the Parsec combinators. |
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 DeriveFunctor, DeriveFoldable, DeriveTraversable #-} | |
{- | |
tree they help | |
2854 8531 8422 2955 | |
t= r= e= h= y= l= p= | |
-} | |
module Decode 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
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 |
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 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) |
OlderNewer