Skip to content

Instantly share code, notes, and snippets.

View felipexpert's full-sized avatar
🎯
Focusing

FtheBuilder felipexpert

🎯
Focusing
View GitHub Profile
-- To run, you will need the Haskell Platform
-- $> runhaskell flatten.hs
data Node a = Single a
| Many [Node a]
deriving Show
flatten :: [Node a] -> [a]
flatten [] = []
flatten ((Single v):xs) = v : flatten xs
flatten ((Many xs):xs') = flatten xs ++ flatten xs'
main = putStrLn $ unlines $ map (`replicate` '*') [1..5]
import Prelude hiding (tail)
import Data.List (find)
import Control.Monad.State (State,put,get,runState)
type VarName = String
type Variable a = (VarName, a)
type Stack a = [Variable a]
test :: State (Stack String) String
test = do
@felipexpert
felipexpert / graham.hs
Created October 24, 2015 14:47
Convex Hull - Graham's algorithm
import qualified Data.List as L
data Direction = Left' | Straight' | Right' deriving (Show, Read, Eq)
data Point = Point Double Double deriving (Show, Read, Eq)
data LineSegment = LineSegment Point Point deriving (Show, Read)
graham :: [Point] -> [Point]
graham = graham' . sort