Skip to content

Instantly share code, notes, and snippets.

✍️

Joseph Abrahamson tel

✍️
Block or report user

Report or block tel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View AssocIn.hs
{-# 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 Apr 18, 2017
Pure profunctor lenses in Scala
View Lenses.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 {
View Maia.scala
package com.jspha.maia
import scala.language.higherKinds
import shapeless._
import shapeless.ops.hlist.Mapped
trait Maia {
trait Api {
type Fields <: HList
View Yana.hs
-- 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 Mar 18, 2017
Maia in Haskell
View Maia.hs
{-# 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 Nov 20, 2016
Indentation sensitive parser combinators
View indents.md

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 Nov 2, 2016
Quantities and quantified sets
View Quantity.scala
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] {
View CommsExample.scala
// 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()
View Nimber.scala
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 Jun 21, 2016
Scala profunctor lens
View Lens.scala
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
You can’t perform that action at this time.