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
{-# 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 |
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 #-} | |
class Collection c where | |
type Element c | |
insert :: Element c -> c -> c | |
instance Collection [a] where | |
type Element [a] = a | |
insert = (:) |
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
-- 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 |
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 |
OlderNewer