Skip to content

Instantly share code, notes, and snippets.

@danbst
danbst / brainfuck.hs
Last active August 29, 2015 14:00
Simple BF interpreter in 38 lines - check http://ideone.com/aLrtPu for online test
{-# LANGUAGE MultiWayIf, BangPatterns #-}
import Data.Word
import Data.Char
data Tape = Tape { negatives :: [Word8], currentTape :: !Word8, positives :: [Word8] }
mkTape = Tape (repeat 0) 0 (repeat 0)
shiftLeft (Tape (x:left) curr right) = Tape left x (curr:right)
shiftRight (Tape left curr (x:right)) = Tape (curr:left) x right
@tom-galvin
tom-galvin / c-machine.hs
Last active August 29, 2015 14:17
DailyProgrammer Challenge #208h Solution (The Universal Machine)
-- My eyes! The goggles do nothing!
import Data.Char
import Data.List
import Data.Maybe
import qualified Data.Map.Strict as Dm
type Symbol = Char
type Alphabet = [Symbol]
type State = String
@nasser
nasser / core.clj
Last active September 30, 2015 20:51
LIES core
(ns lies.core
(:use arcadia.core
lies.messages)
(:require arcadia.messages
[clojure.edn :as edn]))
(defn- type? [t]
(isa? (type t) Type))
(defn- type-map [m]
@erantapaa
erantapaa / bowl.lhs
Last active November 8, 2015 13:26
using parsec to score a bowling game
Using Parsec to score a bowling game.
===
In this gist we'll see how to use Parsec to solve the problem of
scoring a bowling game. This was inspired by a
Reddit Daily Programmer problem:
https://www.reddit.com/r/dailyprogrammer/comments/3ntsni/20151007_challenge_235_intermediate_scoring_a/
module Liars where
import Control.Monad
import Data.List
data Person = Truthteller | Liar deriving (Show, Eq)
says :: Person -> Bool -> Bool
says Truthteller = id
says Liar = not
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE Rank2Types #-}
@paf31
paf31 / Juggling.elm
Last active December 17, 2015 16:29
Juggling in Elm
pauseTime = 0.35
timePerThrow = 300
handMovement = 0.2
pattern = [5]
rotatePattern : Int -> [a] -> [a]
rotatePattern n xs =
@jpt4
jpt4 / lc2016-unconf.txt
Created May 29, 2016 17:02
LambdaConf 2016 Unconference Schedule (Tentative)
UTC20160530
LambdaConf 2016 Unconference Schedule (Tentative)
A115
1:00 - 3:00 PM
Engineering a Better Twitter panel
3:00 - 3:30 PM
0 - Becoming a LambdaConf Speaker
@Icelandjack
Icelandjack / newtype_wrappers.markdown
Last active November 26, 2017 18:19
Newtype wrappers for deriving

Getting Num, Floating, Fractional from Applicative

newtype WrappedApplicative f a = WrapApplicative (f a)
  deriving 
    (Functor, Show)
  deriving newtype 
    Applicative

instance (Applicative f, Num a) => Num (WrappedApplicative f a) where
@merijn
merijn / MyState.hs
Last active January 15, 2021 19:20
MyState homework
data MyState s a = MyState (s -> (a, s))
get :: MyState s s
get = undefined
put :: s -> MyState s ()
put = undefined
modify :: (s -> s) -> MyState s ()
modify = undefined