Skip to content

Instantly share code, notes, and snippets.

View ploeh's full-sized avatar

Mark Seemann ploeh

View GitHub Profile
{-# LANGUAGE DeriveFunctor #-}
module PollingConsumer where
import Data.Time.Clock
import Control.Monad.Trans.Free (Free, FreeF(..), liftF, runFree)
import Control.Concurrent (threadDelay)
import System.Random (getStdRandom, random, randomR)
import Text.Printf (printf)
-- "Types prevent typos" - https://twitter.com/hmemcpy/status/867647943108681728
-- Translation to Haskell of:
-- http://ccd-school.de/2017/06/stratified-design-over-layered-design
-- I've deliberately translated each method to a function, in order to show the
-- similarity. Some functions, like extractWords, are redundant (already built
-- in) or almost too simple to get their own function.
module Main where
import Data.List (partition)
@ploeh
ploeh / Maybe.cs
Last active September 8, 2019 19:54
Skeleton Maybe in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ploeh.Samples.ChainOfResponsibility
{
public class Maybe<T>
{
@ploeh
ploeh / Foo.cs
Created January 26, 2018 09:40
Enumerating over generic and non-generic enumerators in C#
using System;
using System.Collections;
using System.Collections.Generic;
public class Foo : IEnumerable<int>
{
public IEnumerator<int> GetEnumerator()
{
yield return 42;
yield return 1337;
module RadioCode where
import Control.Arrow
import Data.Char
import Data.List
import Data.Maybe
icao :: [(Char, String)]
icao =
(head &&& delete ',')