Skip to content

Instantly share code, notes, and snippets.

View mstksg's full-sized avatar

Justin Le mstksg

View GitHub Profile
@mstksg
mstksg / gist:50ab748e13a72731f1b25098d823138e
Last active May 10, 2018 06:54 — forked from jchia/gist:9697ba86030ef5aa0cdfca48e2e0cbe6
How to get the HasNames instances less manually?
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveDataTypeable #-}
import ClassyPrelude
import Control.Lens
import Data.Typeable
import Data.Data
newtype Name = Name Text deriving (Monoid, Semigroup, IsString, Show, Typeable)
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE TypeInType #-}
data These a b = Neither
| This a
| That b
| These a b
@mstksg
mstksg / bpop.hs
Last active January 31, 2018 07:48
polymorphic backprop
#!/usr/bin/env stack
-- stack --install-ghc runghc --package type-combinators --package ad --package lens --package vector --package reflection -- -Wall
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
@mstksg
mstksg / the_fools_who_dream.md
Last active September 25, 2017 22:04
The Fools Who Dream
title subtitle author
The Fools Who Dream
(Computer Science Edition)
Justin Hurwitz (Lyrics Justin Le)

[Charles Babbage]

His difference engine / did multiplication
And sometimes addition by three

{-# language DeriveFunctor #-}
{-# language UndecidableInstances #-}
{-# language TypeInType #-}
{-# language TypeOperators #-}
{-# language TemplateHaskell #-}
{-# language KindSignatures #-}
{-# language DataKinds #-}
{-# language ViewPatterns #-}
{-# language GADTs #-}
{-# language TypeFamilies #-}
@mstksg
mstksg / ReflectEq.hs
Created August 23, 2017 21:47
reflection for dynamic Eq instances
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.Proxy
import Data.Reflection
data EqDict a = EQD { withEqDict :: a -> a -> Bool }
data Auto1 a b = A1 { runAuto :: a -> (b, Auto1 a b) }
data Auto2 a b = forall s. A2 s ((a, s) -> (b, s))
sumFrom1 :: Int -> Auto1 Int Int
sumFrom1 n = A1 $ \x -> (x + n, sumFrom1 (x + n))
sumFrom2 :: Int -> Auto2 Int Int
sumFrom2 n0 = A2 n0 $ \(x, n) -> (x + n, x + n)
@mstksg
mstksg / prep-ghcjs.md
Created May 20, 2017 09:37
Preparing GHCJS for Stack

Hello

Just writing this down so I don't go crazy and forget later. Let's build a fresh copy of ghcjs from scratch and package it in a way that stack appreciates.

$ git clone git@github.com:ghcjs/ghcjs.git
$ cd ghcjs
$ git checkout ghc-8.0
$ echo "resolver: lts-7.22" > stack.yaml
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude #-}
data ProdMap :: (a -> b -> Type) -> [a] -> [b] -> Type where
PMZ :: ProdMap f '[] '[]
PMS :: f a b -> ProdMap f as bs -> ProdMap f (a ': as) (b ': bs)
data Slice :: Nat -> Nat -> Type where
Slice :: Sing l -> Sing c -> Sing r -> Slice (l + c + r) c
slice
:: (SingI ns, SingI ms)
=> ProdMap Slice ns ms