Skip to content

Instantly share code, notes, and snippets.

View tel's full-sized avatar
✍️

Joseph Abrahamson tel

✍️
View GitHub Profile
@tel
tel / AssocIn.hs
Last active October 17, 2017 03:29
{-# LANGUAGE GADTs #-}
module Lib where
import qualified Data.HashMap.Lazy as M
import Data.Hashable
import Data.Typeable
-- this is what we know about all things from Java
data Val where
@tel
tel / Lenses.scala
Created April 18, 2017 04:38
Pure profunctor lenses in Scala
import scala.language.higherKinds
object Lenses {
trait Profunctor[P[_, _]] {
def dimap[A, B, C, D](f: C => A, g: B => D)(p: P[A, B]): P[C, D]
}
object Profunctor {
@tel
tel / Maia.scala
Last active December 13, 2020 18:57
package com.jspha.maia
import scala.language.higherKinds
import shapeless._
import shapeless.ops.hlist.Mapped
trait Maia {
trait Api {
type Fields <: HList
@tel
tel / Yana.hs
Last active March 30, 2017 05:46
-- Example code
example :: (Context m, MonadLog m, AreaDao m) => [Actor] -> m ()
example list =
forM list $ \actor -> do
logInfo $ "Actor being read: " ++ actorCode actor
areaList <- getArea actor
case areaList of
[] -> return () -- do nothing
(area : _) -> do
@tel
tel / Maia.hs
Created March 18, 2017 18:46
Maia in Haskell
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
@tel
tel / indents.md
Created November 20, 2016 19:47
Indentation sensitive parser combinators

Indentation sensitive parser combinators

An indentation sensitive parser combinator language is one that helps you express ideas like "this parse only succeeds if it's within the current indentation block". The concept is somewhat small and elegant and is implemented in a few libraries. In this writeup, I will use examples from indents.

Background and goal

The direct goal will be to write the sameOrIndented parser combinator with a type

@tel
tel / Quantity.scala
Created November 2, 2016 21:59
Quantities and quantified sets
package jspha.comms
import scala.language.higherKinds
sealed trait Quantity {
type T[_]
}
object Singular extends Quantity { self =>
case class T[A](v: A) extends Quantity.Set[A] {
@tel
tel / CommsExample.scala
Created November 2, 2016 19:50
Comms example
// Given an interface like
sealed trait Mult
sealed trait One extends Mult
sealed trait ZeroOrOne extends Mult
sealed trait Many extends Mult
case class NoParam()
@tel
tel / Nimber.scala
Created July 8, 2016 12:10
Scala Nimbers
import scala.language.implicitConversions
class Nimber(val value: BigInt) extends AnyVal {
def size: Int = {
val bitSize =
if (value == 1) 0
else if (value <= 3) 1
else value.bitLength - 1
val logBits =
@tel
tel / Lens.scala
Created June 21, 2016 14:31
Scala profunctor lens
import scala.language.higherKinds
import scala.language.implicitConversions
trait Pt[C[_[_, _]], S, T, A, B] {
def apply[~>[_, _]](ex: C[~>])(p: A ~> B): S ~> T
}
trait Profunctor[~>[_, _]] {
def dimap[X, Y, A, B](f: X => A, g: B => Y)(p: A ~> B): X ~> Y