Skip to content

Instantly share code, notes, and snippets.

:leyal@leyal-desktop:~/personal/devel/haskell/irc$ hlint rovar.hs
rovar.hs:15:1: Error: Redundant do
Found:
do loadDir "basic_types" >> loadDir "complex" >>
loadDir "single_types"
Why not:
loadDir "basic_types" >> loadDir "complex" >>
loadDir "single_types"
rovar.hs:18:20: Warning: Redundant brackets
{-# OPTIONS -Wall -O2 #-}
module Consumer(ConsumerState(..), Consumer(..), allowsMore, done, returnI, main) where
-- TODO: When "m" is a strict monad, we can't really output
-- intermediate results in consumers! May be better to also have
-- Translator that produces a result after every input.
data ConsumerState m i o =
AllowsMore {
@Peaker
Peaker / lisp.hs
Created May 1, 2011 11:51
Minimal Lisp in Haskell
{-# LANGUAGE OverloadedStrings #-}
{- To Run:
Load in ghci
:set -XOverloadedStrings (for convenience)
Execute repl expr -}
import Control.Applicative
import Control.Monad.State.Strict
import Data.Function
@Peaker
Peaker / test.hs
Created June 4, 2012 00:35 — forked from dtchepak/test.hs
Illegal instance declaration, flexible instances?
{-# LANGUAGE TypeFamilies #-}
class Collection c where
type Element c
insert :: Element c -> c -> c
instance Collection [a] where
type Element [a] = a
insert = (:)
-- my implementation of this: http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf
import qualified Data.PSQueue as DQ
insertThenDel k p pq = DQ.deleteMin $ DQ.insert k p pq
minPriority pq =
case DQ.findMin pq of
(Just m) ->
let mp = DQ.prio m
@Peaker
Peaker / AST.hs
Last active August 29, 2015 14:05
-- Simple Lambda Calculus
data Body a = Var String | Lam String (Expr a) | Apply (Expr a) (Expr a)
deriving (Functor, Foldable, Traversable)
data Expr a = Expr (Body a) a
deriving (Functor, Foldable, Traversable)
Now each sub-expression in (Expr a) has associated data of type "a" which is really useful!
NEXT:
@Peaker
Peaker / ExampleOut.hs
Created September 2, 2014 21:42
Lamdu's new type system
(\id -> id) (\x -> x) :: forall a2. a2 -> a2
((\id -> id{3}){2} (\x -> x{5}){4}){1}
1 = a2 -> a2
2 = (a2 -> a2) -> a2 -> a2
3 = a2 -> a2
4 = a2 -> a2
5 = a2
(\id -> id id) (\x -> x)
Occurs check fails: a1 vs. a1 -> a2
(\id -> id id) (\x -> (\y -> y) x)
@Peaker
Peaker / testftgl.hs
Created January 7, 2015 14:35
Visualize FTGL indicators
import Control.Monad
import Data.IORef
import System.Environment (getArgs)
import System.Mem.Weak (addFinalizer)
import qualified Graphics.Rendering.FTGL as FTGL
import qualified Graphics.Rendering.OpenGL.GL as GL
import qualified Graphics.UI.GLFW as GLFW
resX, resY :: Int
resX = 640
@Peaker
Peaker / indexable.hs
Last active August 29, 2015 14:16 — forked from sinelaw/indexable.hs
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
class Indexable a where
instance c ~ Char => Indexable (String, Int, c) where
instance Indexable ([(String, a)], String, a) where
@Peaker
Peaker / gist:9e1d87e81945184871e4
Created June 1, 2015 19:24
Weird error about immutability
import tables, strutils
proc getFrequencies() : CountTable[string] =
let wordFrequencies = initCountTable[string]() # <-- this should be var
for line in open("example1.nim").lines():
for word in line.split(", "):
wordFrequencies.inc(word)
return wordFrequencies