600.429 functional programing at work - haskell and domain specific languages dr. john peterson...
TRANSCRIPT
600.429FUNCTIONAL PROGRAMING AT WORK -
HASKELL AND DOMAIN SPECIFIC LANGUAGES
Dr. John PetersonWestern State Colorado University
Project Pitch
Let’s talk! I’ll set up wiki accounts tonightGood things:• A well defined scope that allows an incremental
approach• Pre-existing infrastructure• A compositional point of view (building-block
pieces + combining functions)• Novel semantic foundation (reactive
programming, for example)
Quiz 4
Advantages / disadvantages of Haskell embeddingEuterpea expressions that are the same in Euterpea but not Haskell. Why does this matter?What is the semantic model of Euterpea?What does a parser know that a grammar doesn’t?
Homework 5
http://wiki.western.edu/mcis/index.php/429/Week_5
HW5 Project Organization
Phase 1: a parsec parser that converts strings to tokens• Create a data type for lexemes• Drop whitespace• Group characters for variables / numbers• Represent indentation at the start of a line• Don’t worry about error reporting• Test before proceeding!
HW5 Phase 2
Deal with layout (indentation):• Map a list of tokens that includes indentation
to a list that drops indentation and replaces it with a new token, End
• Probably don’t need to use parsec• Need to know all outer indentation levels (list
of int will work)
Phase 2 Strategy
Line indented more than current levelLine indented at current levelLine indented less than current levelHow do we recognize a new level?Assume all blocks have at least one statementIgnore blank lines in lexer
Phase 3 Strategy
Use “End” to mark line end and block endShould look like grammarUse “try” for backtracking. Where do we need to worry about backtracking?
Questions?
Haskell Modules
Modules – group a set of names in a file.Strictly a renaming construct – deals with visibility only.Use modules to encapsulate functionality – like ast.hsYou can do selective export (export lists) or import (import lists)Hierarchical namespace uses “.”
Applicative and Functor
http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Functor.html#v:-60--36--62-http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Applicative.html#v:-42--62-
What do these infix operators do for parsers?
Inside parsec
See http://hackage.haskell.org/package/parsec
Let’s look at “Char”, “Combinator”, and “Prim”
How can we make combinators similar to those in Char with an arbitrary token stream type?