Skip to content

Instantly share code, notes, and snippets.

@solomon-b
solomon-b / TicTacToe.hs
Created January 31, 2019 18:05
Weird TicTacToe
module TicTacToe where
import Control.Applicative
import Control.Monad
import Data.Semigroup hiding (First)
import Data.Monoid hiding ((<>))
data Three = One | Two | Three deriving (Show, Eq)
newtype Tic a = Tic { unTic :: Three -> Three -> Maybe a }
forkReader :: ReaderT r IO () -> ReaderT r IO ThreadId
forkReader action = do
env <- ask
liftIO . forkIO $ runReaderT action env
forkUnliftIO :: MonadUnliftIO m => m () -> m ThreadId
forkUnliftIO r = withRunInIO $ \run -> forkIO (run r)

MayDay/BeacHac Call for Speakers

Please join us for a weekend of Haskell/Purescript lectures and hacking in the spirit of BayHac (but in LA!). We are looking for speakers to do 30-45minute presentations on any topics related to Haskell and Purescript. We are also looking for open source maintainers who would like to present their Haskell/Purescript for contributions during our open hacking sessions. Please send proposals to [email protected]

When

25-26 May 2019

Where

@solomon-b
solomon-b / monadTransformerDemo.hs
Created March 13, 2019 17:49
Demonstration of Reader/Exception/IO Monad Transformer stack constructions from basic Monads to MTL.
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
module ExceptionTest where
import Control.Concurrent
import Control.Exception
import Control.Monad
@solomon-b
solomon-b / Parser.hs
Created March 29, 2019 03:30
Toy Parser inspired by Stephen Diehl's NanoParsec and Edward Kmett's Trifecta
module Parser where
-- Toy Parser inspired by Stephen Diehl's NanoParsec and Edward Kmett's Trifecta
-- Solomon Bothwell
import Control.Applicative
import Control.Monad
import Control.Monad.Fail
import Data.Char
@solomon-b
solomon-b / ChurchEncoding.hs
Created April 4, 2019 17:48
This is old and most likely broken
module ChurchEncoding where
newtype Church a = Church { unChurch :: (a -> a) -> a -> a }
church :: Integer -> Church Integer
church 0 = Church $ \f -> \x -> x
church n = Church $ \f -> \x -> f $ unChurch (church (n - 1)) f x

NOTES:

Lists

There is only one type of list and it is constructed using cons cells (aka 2-tuples):

(a,  b)
-- Calculates all possible combination of coins totally the input value
newtype Coin = Coin Int deriving Show
newtype Forest = Forest [(Coin, Forest)] deriving Show
makeBaseFunctor ''Forest
coalgebra :: [Coin] -> Int -> ForestF Int
coalgebra coins i =
ForestF $ (\(Coin den) -> [(Coin den, i - den) | i >= den]) =<< coins
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Main where
{-
When writing programs in a statically typed language such as Haskell,
there are two concepts we often think about and try to reconcile:
Generic Programming - Generally extensible and repurposable code. (This
module Main where
import Data.Bifunctor
import Lib
type World = Pos -> Bool
type Pos = (Int, Int)
{-
2-3 Neighbors = Alive