Skip to content

Instantly share code, notes, and snippets.

module ZipAndSplit where
import Prelude hiding (map, filter)
import Data.Either
-- Demonstrate the duality between zip and split
-- Typedefinition of streams and the fundamental operations on them
data Stream a
map :: Stream a -> (a -> b) -> Stream b
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE GADTs #-}
module Generators where
import Test.QuickCheck
import Data.Proxy
import Data.Coerce
@txsmith
txsmith / MutualApplicative.hs
Created March 8, 2019 13:16
Mutual applicatives
{-# Language MultiParamTypeClasses #-}
module MutualApplicative where
import Control.Applicative
data Either2 f g a =
Left2 (f a)
| Right2 (g a)
deriving (Functor)
@txsmith
txsmith / SExprParser.scala
Created February 17, 2019 12:04
S-Expression parser
object SExprParser {
import scala.util.parsing.combinator._
sealed abstract class SExpr
case class SList(list: List[SExpr]) extends SExpr
case class SSym(symbol: String) extends SExpr
case class SNum(num: Int) extends SExpr
case class SString(string : String) extends SExpr
case class ReaderException(msg:String) extends RuntimeException(msg)
@txsmith
txsmith / Fixing.scala
Last active February 15, 2019 12:39
Fixing an AST where leaf nodes may be unknown
import scala.language.higherKinds
object Fixing {
// String representation of a rule expression
type UnknownRule = String
type LocationID = String
@txsmith
txsmith / TreesThatGrow.scala
Last active August 21, 2023 08:26
An attempt at Trees That Grow in Scala
import scala.annotation.{implicitAmbiguous, implicitNotFound, showAsInfix}
import scala.language.higherKinds
/**
* This is an attempt to replicate Trees that Grow by Shayan Najd and Simon Peyton Jones in Scala.
* Paper at: https://www.microsoft.com/en-us/research/uploads/prod/2016/11/trees-that-grow.pdf
* The main mechanisms demonstrated in the paper can be recreated in Scala but at a significant boilerplate cost.
* The best approach to improve this would be to automatically generate the appy and unapply methods for each AST term
* (e.g. with a macro or code generation)
*/

Keybase proof

I hereby claim:

  • I am txsmith on github.
  • I am tnsmith (https://keybase.io/tnsmith) on keybase.
  • I have a public key ASDjfSE-btAFor86svX0rYm1CMrmD2IT62qbIHjqRYPqkAo

To claim this, I am signing this object: