Skip to content

Instantly share code, notes, and snippets.

@vmchale
vmchale / ghcjs.sh
Last active July 29, 2018 01:48
Bash script to install GHCJS
#!/usr/bin/env bash
set -ex pipefile
cd "$HOME" || exit
cabal new-update
cabal new-install hscolour
rm -f "$HOME/.local/bin/cabal" "$HOME/.cabal/bin/cabal"
rm -rf "$HOME/.ghcjs"
cabal new-install cabal-install --constraint='cabal-install == 1.24.0.2' -w ghc-8.0.2
@vmchale
vmchale / main.c
Last active September 5, 2019 18:39
Monkey patching C
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
int getpagesize(void);
void n_primes(int);
@vmchale
vmchale / install-ghcjs.sh
Last active April 17, 2019 00:12
This is the bash script I use to install GHCJS (8.6) on Linux
#!/usr/bin/env bash
# forked from Moritz Angerman https://github.com/angerman/haskell-to-web/blob/master/ghcjs-build-notes.org
set -e pipefail
cabal new-install happy --overwrite-policy=always
cabal new-install alex --overwrite-policy=always
cabal new-install hscolour --overwrite-policy=always
cabal new-install hsc2hs --overwrite-policy=always
@vmchale
vmchale / cowsay.dhall
Created July 9, 2020 01:57
Cowsay using pure functional programming
let cowsay =
λ(txt : Text) →
''
${txt}
------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
@vmchale
vmchale / xor.ijs
Last active June 6, 2021 14:19
Port a Python neural network to J
NB. I used https://towardsdatascience.com/implementing-the-xor-gate-using-backpropagation-in-neural-networks-c1f255b4f20d
NB. input data
X =: 4 2 $ 0 0 0 1 1 0 1 1
NB. target data, ~: is 'not-eq' aka xor
Y =: , (i.2) ~:/ (i.2)
scale =: (-&1)@:(*&2)
@vmchale
vmchale / parse.curry
Last active April 24, 2024 03:37
Parser in Curry (fl-parser 3.0.0)
-- cypm add fl-parser
-- ported from: https://www-ps.informatik.uni-kiel.de/~cpm/DOC/fl-parser-3.0.0/Parser_curry.html
import Parser
num = Parser.some digit l >>> numeric_value l
where l free
numeric_value ds = foldl1 (\acc x -> 10*acc+x) (map (\c -> ord c-ord '0') ds)
expr = term m Parser.<*> terminal '+' Parser.<*> expr n >>> m+n
<||> term m Parser.<*> terminal '-' Parser.<*> expr n >>> m-n