Matthías Páll Gissurarson, @tritlo
Reykjavík Functional Programming
2020-07-31
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
{-# 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} |
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) |
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] |
{-# 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 |
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/ \ |
{-# LANGUAGE RebindableSyntax #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE TypeInType #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE PartialTypeSignatures #-} | |
{-# LANGUAGE DeriveDataTypeable #-} |
{-# 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 |