Skip to content

Instantly share code, notes, and snippets.

View ploeh's full-sized avatar

Mark Seemann ploeh

View GitHub Profile
module Main where
import Control.Monad.Eff (Eff)
import Data.Maybe (fromJust)
import Data.Tuple (Tuple(..))
import Graphics.Canvas (CANVAS, Context2D, closePath, getCanvasElementById,
getContext2D, lineTo, moveTo, setLineWidth, strokePath)
import Math (cos, pi, sin)
import Partial.Unsafe (unsafePartial)
import Prelude (Unit, bind, discard, negate, void, ($), (*), (+), (-), (/), (<=))
@ploeh
ploeh / FractalTree.fsx
Created June 6, 2017 11:22
Fractal tree in F#. Our solution from dojo in Copenhagen, 2017-05-30
open System
open System.Drawing
open System.Windows.Forms
// Create a form to display the graphics
let width, height = 500, 500
let form = new Form(Width = width, Height = height)
let box = new PictureBox(BackColor = Color.White, Dock = DockStyle.Fill)
let image = new Bitmap(width, height)
let graphics = Graphics.FromImage(image)
@ploeh
ploeh / Safefs.hs
Last active March 29, 2022 18:37
Safe head function using Either in Haskell
safeHead [] = Left "The list was empty. No head is available."
safeHead xs = Right . head $ xs
-- Sample usage from GHCI:
--
-- *Safefs> safeHead [1..3]
-- Right 1
-- *Safefs> safeHead [7]
-- Right 7
-- *Safefs> safeHead [2, 3]
@ploeh
ploeh / Tuple2.fs
Last active December 2, 2022 14:11
Helpful functions for working with pairs in F#
module Tuple2
let replicate x = x, x
let curry f x y = f (x, y)
let uncurry f (x, y) = f x y
let swap (x, y) = (y, x)
@ploeh
ploeh / ApiModel.hs
Last active December 24, 2022 22:54
Handling a reservation request in Haskell. Proof of concept
module ApiModel where
import Data.Time (ZonedTime(..), parseTimeM, defaultTimeLocale, iso8601DateFormat)
data ReservationRendition = ReservationRendition
{ rDate :: String
, rName :: String
, rEmail :: String
, rQuantity :: Int }
deriving (Eq, Show, Read)