Skip to content

Instantly share code, notes, and snippets.

(module test-module (quote #%builtin-kernel)
(#%plain-module-begin
(#%require /libs/racket/base)
(#%provide test-result)
(#%require /libs/racket/private/syntax-case)
(define-syntax defun
(#%plain-lambda (stx)
(#%plain-app
(#%variable-reference console-log)
(#%variable-reference stx)
#lang racket
(define a 1)
(define b 2)
; quote
'(+ a b) ; '(+ a b)
; quasiquote
`(+ a ,b) ; '(+ a 2)
; nested quasi-quote expr
#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) =
#!/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
{-# LANGUAGE NumericUnderscores #-}
import Control.Monad (replicateM_, void)
import Criterion.Main
import Data.Foldable (foldl', foldr)
main :: IO ()
#!/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
@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
{- |
DESCRIPTION
This program parses valid NRICs from text.
NRICs are unique identification numbers given to Singaporeans and Permanent residents of Singapore.
SYSTEM
This runs on GHC 8.10.1
These libraries should be included with your GHC distribution: