Skip to content

Instantly share code, notes, and snippets.

View throughnothing's full-sized avatar

William Wolf throughnothing

View GitHub Profile
@throughnothing
throughnothing / purescript-gadt.purs
Created December 6, 2018 20:28
Purescript GADT example
module GADT.Main where
import Prelude (class Category, class Semigroupoid, (<<<), flip, identity, ($), (+), (==))
import Unsafe.Coerce (unsafeCoerce)
newtype Leibniz a b = Leibniz (forall f. f a -> f b)
infix 4 type Leibniz as ~
instance semigroupoidLeibniz :: Semigroupoid Leibniz where
@throughnothing
throughnothing / MontyHall.purs
Last active June 10, 2020 17:55
Monty Hall
module MontyHall.Main where
import Prelude
import Data.Foldable (foldr)
import Data.List.Lazy (range)
import Data.Tuple (Tuple(..))
import Debug.Trace (class DebugWarning, spy)
import Effect (Effect)
import Effect.Random (randomInt)
@throughnothing
throughnothing / Algebra.purs
Created December 4, 2018 19:33 — forked from LukaJCB/Algebra.purs
Alternative Tagless Final encoding in PureScript
module Algebra where
import Prelude
import Control.Monad.Eff (Eff)
import Data.Maybe (Maybe(..))
newtype ConsoleAlg f = ConsoleAlg
{ printLn :: String -> f Unit
, readLn :: f String
@throughnothing
throughnothing / Money.java
Last active August 23, 2018 17:13
Phantom Types in Java for Number Constraints
import com.sun.istack.internal.NotNull;
import static io.vavr.API.*;
import io.vavr.collection.List;
import io.vavr.control.Option;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Value;
import java.math.BigDecimal;
@throughnothing
throughnothing / Loeb.purs
Last active October 8, 2018 17:29
Loeb in Purescript
module Loeb where
import Prelude
import Data.Lazy (Lazy, defer, force)
import Data.Array ((!!))
import Data.Maybe (fromMaybe)
loeb :: ∀ f a. Functor f => f (f (Lazy a) -> a) -> f (Lazy a)
loeb x = go where go = map (\y -> defer (\_ -> y go)) x
@throughnothing
throughnothing / collatz.purs
Last active August 14, 2018 16:31
Collatz Purescript
module Collatz where
import Prelude (div, otherwise, (==), (*), (+), (>), ($), map)
import Data.Array (length)
import Data.Ord (class Ord)
import Data.Semiring (class Semiring, zero)
import Data.Functor (class Functor)
import Data.Int (even)
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))
@throughnothing
throughnothing / monoidtries.purs
Last active August 12, 2018 07:55
Words Tries where Tries are Monoids
module Main where
import Prelude (($), (<>), map, (<<<))
import Data.Map as M
import Data.Ord (class Ord)
import Data.Semigroup (class Semigroup)
import Data.Monoid (class Monoid, mempty)
import Data.Show (class Show, show)
import Data.String.CodeUnits (toCharArray)
import Data.Foldable as F
@throughnothing
throughnothing / wordztrie.purs
Last active August 12, 2018 00:43
Trie from list of words in Purescript
module Main where
import Prelude (($))
import Data.Map (Map, empty, lookup, insert)
import Data.Ord (class Ord)
import Data.String (toCodePointArray, CodePoint)
import Data.Foldable (foldl)
import Data.Maybe (fromMaybe)
import Data.List (List(..), (:), fromFoldable)
@throughnothing
throughnothing / bitcoin_cash_addresses.js
Last active January 15, 2018 23:00
Parse all 3 Bitcoin Cash Address formats into a bitcore Address object
var cashaddrjs = require('cashaddrjs');
var bitcore = require('bitcore-lib');
var bitcoreCash = require('bitcore-lib-cash');
// Get a bitcore.Address object for any address type
// - Legacy (BTC-style)
// - Copay (BitPay, probably will be deprecated?)
// - Cashaddr (new BCH format)
var getAddressObj = function(addressStr) {
try {
@throughnothing
throughnothing / demo.idr
Last active August 22, 2018 06:11
Dependent Types Demo Code
import Data.Fin
import Data.So
-- %default total