Skip to content

Instantly share code, notes, and snippets.

View heath's full-sized avatar
❄️
λΠ

heath

❄️
λΠ
View GitHub Profile
@heath
heath / blc.S
Created January 20, 2023 15:38 — forked from jart/blc.S
Binary Lambda Calculus Virtual Machine for x64 Linux in 400 bytes
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2022 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
@heath
heath / running-haskell-scripts.md
Last active May 26, 2020 22:39 — forked from monadplus/running-haskell-scripts.md
Running a haskell script without GHC using nix
#!/usr/bin/env nix-shell
#nix-shell -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [ mwc-random ])" -i runghc

{-# LANGUAGE ScopedTypeVariables #-}

import System.Random.MWC
import Data.Vector.Unboxed
import Control.Monad.ST
@heath
heath / TestingCFromHaskell.hs
Created February 17, 2020 05:03 — forked from gelisam/TestingCFromHaskell.hs
using Haskell's QuickCheck to property-test C's qsort
-- in response to https://www.reddit.com/r/haskell/comments/duopq8/create_tests_for_other_languages_using_haskell/
-- TLDR: yes, you can test C functions from Haskell; it's a bit painful to
-- call C from Haskell, but once you do, testing is the easy part!
{-# LANGUAGE QuasiQuotes, ScopedTypeVariables, TemplateHaskell #-}
module Main where
import Data.Foldable (for_)
import Data.Traversable (for)
import Foreign.C.Types (CInt, CSize)
@heath
heath / Json.purs
Created February 15, 2020 17:13 — forked from i-am-tom/Json.purs
Parsing, Generating, and Diffing JSON in PureScript
module Main where
-- | JSON is an incredibly simple format. Even its lists are untyped.
-- | As with all languages, functional programming encourages us to
-- | make a domain-specific language (or DSL) to capture the "ideas"
-- | of the language, which we can then use to talk about its content.
-- | In this little snippet, we'll build a JSON DSL, transform it into
-- | a recursive structure, and then use that result to generate some
module Main where
-- Challenge: rudimentary spam filter
-- given the sample blacklist and comments check to see if
-- the phrases in the blacklist are in the comment
import Data.List (isInfixOf)
type BlackList = [String]
type Comment = String
module Main where
-- | emulate a tennis game ignoring some of the details
import Lib
import Network.Wreq
import Data.Aeson (Value)
import Control.Lens
@heath
heath / Optics Cheatsheet.md
Created January 3, 2020 03:43 — forked from ChrisPenner/Optics Cheatsheet.md
Optics Cheatsheet
@heath
heath / Main.hs
Last active December 9, 2019 18:48
example of decoding a MisoString into an Either String Aeson.Value
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Miso.String
import qualified Data.Aeson as Aeson
import qualified Data.Text.Lazy.Encoding as E
import qualified Data.Text.Lazy as TL
main :: IO ()
fmap :: ... => (a -> b) -> (f a -> f b)
(.) :: (y -> z) -> (x -> y) -> (x -> z)
fmap :: (f2 a -> f2 b) -> (f1 (f2 a) -> f1 (f2 b))
fmap :: (a -> b) -> (f2 a -> f2 b)
(.) :: (y -> z ) -> (x -> y ) -> (x -> z )
(.) :: ((f2 a -> f2 b) -> (f1 (f2 a) -> f1 (f2 b))) -> ((a -> b) -> (f2 a -> f2 b)) -> ((a -> b) -> (f1 (f2 a) -> f1 (f2 a)))
(.) fmap fmap :: (a -> b) -> (f1 (f2 a) -> f1 (f2 b))
^--- (.) fmap fmap = fmap . fmap