Skip to content

Instantly share code, notes, and snippets.

View Tritlo's full-sized avatar

Matthías Páll Gissurarson Tritlo

View GitHub Profile
@Tritlo
Tritlo / LazinessInAction.md
Last active August 1, 2020 02:34
Talk on Laziness @RVKFP 2020-07-31

Laziness in Action

Matthías Páll Gissurarson, @tritlo

Reykjavík Functional Programming

2020-07-31

@Tritlo
Tritlo / README.md
Created June 26, 2020 00:12
Draugatög @ RFP 2020-06-25

Sæktu https://github.com/tritlo/writ-plugin, búðu til nýja möppu sem heitir TestRFP, bættu því við í cabal.project og afritaðu skjölin hér að ofan í möppuna, og keyrðu svocabal run test_rfp til að keyra

@Tritlo
Tritlo / M.hs
Last active June 26, 2020 00:15
QualifiedDo @ RFP 2020-06-25
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
module M where
import GHC.TypeLits
data Merki = Leyndarmál | Opinbert
newtype LIO (l :: Merki) a = LIO {unLIO :: IO a}
@Tritlo
Tritlo / PrintXY.hs
Created May 27, 2020 08:22
I got nerd sniped to write a function that takes an n, and prints all strings of length n containing only 'X' and 'Y'
import Data.Bits
printXY n = mapM_ print (gen n)
where gen 0 = [""]
gen n = map (f n) [0..2^(n-1)]
f :: Int -> Integer -> String
f n i = map (toXY . testBit i) [0..(n-1)]
toXY c = if c then 'X' else 'Y'
genRec n = (map ('X':) smaller) ++ (map ('Y':) smaller)
where smaller = genRec (n-1)
@Tritlo
Tritlo / favicon.py
Last active June 29, 2019 23:09
Favicon.png
import numpy as np
from PIL import Image
w,h = 384, 384
data = np.zeros((w,h,3), dtype=np.uint8)
yellow = [255, 255,0]
black = [0,0,0]
@Tritlo
Tritlo / ONotation.hs
Created November 5, 2018 10:14
Type-level complexity annotations in Haskell
{-# LANGUAGE TypeInType, TypeOperators, TypeFamilies,
UndecidableInstances, ConstraintKinds #-}
module ONotation where
import GHC.TypeLits as L
import Data.Type.Bool
import Data.Type.Equality
-- Simplistic asymptotic polynomials
data AsymP = NLogN Nat Nat
{-# LANGUAGE GADTs #-}
import Data.List
import Data.Monoid
import Data.Typeable
import Data.Dynamic
import GHC.Err
import GHC.Prim
@Tritlo
Tritlo / Dockerfile
Last active March 13, 2019 00:23
Dockerfile and config for cross compiling Haskell to run on Raspberry Pi
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y curl xz-utils build-essential unzip
RUN mkdir -p /rpi/ghc/ \
&& curl -sSL http://releases.mobilehaskell.org/x86_64-linux/9824f6e473/ghc-8.4.0.20180109-arm-linux-gnueabihf.tar.xz -o ghc.tar.xz\
&& tar -xvf ghc.tar.xz -C /rpi/ghc/\
&& rm -f ghc.tar.xz
RUN mkdir -p /rpi/prebuilt/ \
@Tritlo
Tritlo / OverloadedDo.hs
Last active February 13, 2018 19:06
OverloadedDo exploration
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE DeriveDataTypeable #-}
@Tritlo
Tritlo / Main.hs
Last active January 23, 2018 13:48
Using typed holes to lookup functions with types with non-functional properties.
{-# LANGUAGE TypeInType, TypeOperators #-}
module Main where
import Sorting
import ONotation
-- Here we say that sorted can use at most complexity N^2 and at most memory N^1
-- and that the sort has to be stable.
mySort :: Sorted (O(N ^. 2)) (O(N)) True Integer