Last active
October 19, 2016 03:41
-
-
Save edmundnoble/e4523be0916b4b34fa4b8b9a83a297b8 to your computer and use it in GitHub Desktop.
Dyck language plus strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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