Skip to content

Instantly share code, notes, and snippets.

@edmundnoble
Last active October 19, 2016 03:41
Show Gist options
  • Save edmundnoble/e4523be0916b4b34fa4b8b9a83a297b8 to your computer and use it in GitHub Desktop.
Save edmundnoble/e4523be0916b4b34fa4b8b9a83a297b8 to your computer and use it in GitHub Desktop.
Dyck language plus strings
import scalaz._
import Scalaz._
type DyckTerm = Free[List, Char]
type DyckSentence = List[Free[List, Char]]
// bracket a sentence
def bracket(f: DyckSentence): DyckTerm = Free.roll[List, Char](f.toList)
// convenient overload
def bracket(f: DyckTerm*): DyckTerm = bracket(f.toList)
def lit(s: Char): DyckTerm = Free.pure[List, Char](s)
// AB(C(D)D)
val testSentence: DyckSentence = List(lit('A'), lit('B'), bracket(lit('C'), bracket(lit('D'))), lit('D'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment