This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(\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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE GADTs #-} | |
module KTuple where | |
type family Fst (xs :: (a, b)) :: a where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
: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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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] |
OlderNewer