Skip to content

Instantly share code, notes, and snippets.

@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
@Peaker
Peaker / AttemptedChange
Created June 1, 2015 19:46
Changing the compiler to emit a more informative error -- didn't work
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 2a9d15b..530f226 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -251,7 +251,7 @@ proc describeArgs*(c: PContext, n: PNode, startIdx = 1;
arg = c.semOperand(c, n.sons[i])
n.sons[i] = arg
if arg.typ.kind == tyError: return
- add(result, argTypeToString(arg, prefer))
+ add(result, typeToString(arg.typ, prefer))
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE GADTs #-}
module KTuple where
type family Fst (xs :: (a, b)) :: a where
: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 / hangman.hs
Last active October 4, 2015 11:08 — forked from ToJans/hangman.hs
A haskell implementation of the hangman game
{-# OPTIONS -Wall #-}
import Control.Monad (when, unless)
import Data.Char (toLower)
import Data.List (transpose)
import System.Random (randomIO)
wordsPath :: FilePath
wordsPath = "/usr/share/dict/words"
addHangImage :: [String] -> [String]