Skip to content

Instantly share code, notes, and snippets.

#lang racket
(define-syntax-rule (swap x y)
(let ([tmp x])
(set! x y)
(set! y tmp)))
;; this
(let ([tmp 5]
[other 6])
(swap tmp other) ;; swap also has a tmp in its body, however it is guaranteed to be a different object
a a a a a a
@kwannoel
kwannoel / bf-fold-tree-strict.hs
Created January 4, 2021 06:38
BFS tree fold
#!/usr/bin/env stack
-- stack exec ghc --resolver lts-16.2 --package criterion -- -threaded -O2 -rtsopts -with-rtsopts=-N -eventlog
import Control.Monad (replicateM_, void)
import Criterion.Main
import Data.Foldable (foldl')
import Data.Tree
treeFoldStrict :: (b -> [a] -> b) -> b -> Tree a -> b
treeFoldStrict f init (Node val children) =
@kwannoel
kwannoel / haskeller_competency_matrix.md
Created December 18, 2020 05:27 — forked from graninas/haskeller_competency_matrix.md
Haskeller competency matrix

Haskeller Competency Matrix

See also List of materials about Software Design in Haskell

Junior Middle Senior Architect
Haskell level Basic Haskell Intermediate Haskell Advanced Haskell Language-agnostic
Haskell knowledge scope Learn you a Haskell Get programming with Haskell Haskell in Depth Knows several languages from different categories
Get programming with Haskell Haskell in Depth Functional Design and Architecture
[Other books on Software Engineering in Haskell](https://github.com/graninas/software-design-in-haskell#Books-on-So
#!/usr/bin/env stack
-- stack exec ghc --resolver lts-16.2 --package time --package async --package text --package deepseq -- -prof -fprof-auto -threaded -O2 -rtsopts -with-rtsopts=-N -eventlog
{-
See if we can reproduce having to repeatedly generate environments
-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE RecordWildCards #-}
#!/usr/bin/env stack
-- stack script --resolver lts-16.2 --package criterion --package relude --package text --package deepseq
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
import Control.DeepSeq (NFData)
import Control.Monad (replicateM_, void)
import Criterion.Main
#!/usr/bin/env stack
-- stack script --resolver lts-16.2 --package criterion
{-# LANGUAGE NumericUnderscores #-}
import Control.Monad (replicateM_, void)
import Criterion.Main
import Data.Foldable (foldl', foldr)
main :: IO ()
@kwannoel
kwannoel / benchmark-async.hs
Last active December 9, 2020 04:00
Benchmarking async
#!/usr/bin/env stack
-- stack exec ghc --resolver lts-16.2 --package async --package criterion -- -threaded -O2 -rtsopts -with-rtsopts=-N
import Control.Concurrent.Async (async, mapConcurrently_)
import Control.Monad (replicateM_, void)
import Criterion.Main
main :: IO ()
main = defaultMain
@kwannoel
kwannoel / yy.hs
Created October 13, 2020 12:20
yy.hs
{- |
REFERENCES:
https://gist.github.com/lukechampine/a3956a840c603878fd9f
https://rosettacode.org/wiki/Y_combinator#Haskell
https://mvanier.livejournal.com/2897.html
GOAL: Implement recursion in languages which do not support **Explicit recursion**
Do so in an intuitive way
PREREQUISITES:
@kwannoel
kwannoel / use-box.dump
Last active July 31, 2020 09:08
Usecase for Rc in Raytracers
error[E0382]: use of moved value: `metal_shiny`
--> temp.rs:39:38
|
37 | let metal_shiny = Metal::new(0.0);
| ----------- move occurs because `metal_shiny` has type `Metal`, which does not implement the `Copy` trait
38 | let sphere1 = Sphere::new(Box::new(metal_shiny));
| ----------- value moved here
39 | let sphere2 = Sphere::new(Box::new(metal_shiny));
| ^^^^^^^^^^^ value used here after move