Skip to content

Instantly share code, notes, and snippets.

@danbst
danbst / brainfuck.hs
Last active Aug 29, 2015
Simple BF interpreter in 38 lines - check http://ideone.com/aLrtPu for online test
View brainfuck.hs
{-# 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 Aug 29, 2015
DailyProgrammer Challenge #208h Solution (The Universal Machine)
View c-machine.hs
-- 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 Sep 30, 2015
LIES core
View core.clj
(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]
@aztek
aztek / Functor.v
Created Jun 11, 2012
Coq Functor type class with statically checked functor laws
View Functor.v
Require Import Coq.Program.Basics.
Require Import Coq.Program.Syntax.
Require Import Coq.Init.Datatypes.
Require Import Coq.Unicode.Utf8.
Open Local Scope program_scope.
Open Local Scope list_scope.
Open Local Scope type_scope.
Class Functor (φ : TypeType) := {
@erantapaa
erantapaa / bowl.lhs
Last active Nov 8, 2015
using parsec to score a bowling game
View bowl.lhs
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/
View Liars.hs
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
View SiteswapTypes.hs
{-# 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 Dec 17, 2015
Juggling in Elm
View Juggling.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
LambdaConf 2016 Unconference Schedule (Tentative)
View lc2016-unconf.txt
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 Nov 26, 2017
Newtype wrappers for deriving
View newtype_wrappers.markdown

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