Skip to content

Instantly share code, notes, and snippets.

-- stack --system-ghc runghc
{- |
Result of pair programming with [bumbleblym](https://github.com/bumbleblym)
He implemented most of the code below and suggested using parsers from base
rather than @getLine@ & @read@ to parse the input.
This increases code modularity and ease of refactoring.
Interesting parts:
@kwannoel
kwannoel / agda.nix
Created July 6, 2020 15:52
Nix shell for agda
# Adapted from @ryanorendorff's gist: https://gist.github.com/ryanorendorff/f5c96d9f363a0e390425c2d9588bbb9d
{ pkgs ? import <nixos> {} }:
let
# The standard library in nixpkgs does not come with a *.agda-lib file, so we
# generate it here.
standard-library-agda-lib = pkgs.writeText "standard-library.agda-lib" ''
name: standard-library
include: ${pkgs.AgdaStdlib}/share/agda
{- |
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:
@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
@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 / 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
#!/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
#!/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 #-}
@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