Skip to content

Instantly share code, notes, and snippets.

@vmchale
vmchale / Graph.hs
Created January 24, 2025 14:23
Shortest path example from §4.4 Escardó & Oliva 2009
module Graph where
import qualified Data.Array as A
import Data.List (find, inits)
type J r x = (x -> r) -> x
data R = Dist Integer
| Infinity deriving Eq
@vmchale
vmchale / CTAGS.md
Last active September 15, 2024 16:14
Jump-to-definition in vim for Happy/Alex macros

Universal ctags can be extended to generate tags for Happy and Alex macros. ghc-tags can already handle functions and types defined therein.

Put the following in ~/.ctags.d/alex.ctags:

--langdef=ALEX
--langmap=ALEX:.x
@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
@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)