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 RankNTypes, DeriveFunctor #-} | |
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-} | |
module Main where | |
import Criterion.Main (defaultMain, bench, bgroup, nf) | |
-------------------------------------------------------------------------------- | |
-- Fixed points of a functor | |
newtype Mu f = Mu { muF :: f (Mu f) } |
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
-- | Something for work, prototyped first in Haskell before turning | |
-- into Scala | |
{-# LANGUAGE DeriveFunctor #-} | |
{-# LANGUAGE DeriveFoldable #-} | |
{-# LANGUAGE DeriveTraversable #-} | |
{-# LANGUAGE LambdaCase #-} | |
import Test.Hspec | |
import Control.Monad.State |
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 OverloadedStrings #-} | |
import Data.String | |
data Value = VInt Int | |
| VString String | |
-- In order to hide the unitype details from the user. | |
instance Show Value where | |
show (VInt i) = show i |
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 Control.Category ((>>>)) | |
data Option = Option { name :: String } | |
-- Point-free style. Is this readable? | |
-- | |
-- An Option matches a String if: we get the name of the Option and then prepend "--" to it, test whether that is equal | |
-- to the given String. | |
matches :: Option -> String -> Bool | |
matches = name >>> ("--" ++) >>> (==) |
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
-- Response to https://twitter.com/mfeathers/status/495979138365149184 | |
-- Based on http://git.zx2c4.com/spark/tree/spark.c | |
import System.IO (hPutStrLn, stderr) | |
import System.Environment (getArgs) | |
import qualified Data.ByteString as B | |
import qualified Data.ByteString.Char8 as C | |
main :: IO () | |
main = do |
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
sealed trait Interact[A] | |
case class Ask(prompt: String) | |
extends Interact[String] | |
case class Tell(msg: String) | |
extends Interact[Unit] | |
trait Monad[M[_]] { | |
def pure[A](a: A): M[A] |
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
// Illustrate disciplined C++ code | |
// http://www.cplusplus.com/reference/vector/vector/ | |
#include <vector> | |
#include <iostream> | |
using namespace std; | |
class Foo { | |
public: |
NewerOlder