600.429 functional programing at work - haskell and domain specific languages dr. john peterson...

12
600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University

Upload: anissa-black

Post on 13-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University

600.429FUNCTIONAL PROGRAMING AT WORK -

HASKELL AND DOMAIN SPECIFIC LANGUAGES

Dr. John PetersonWestern State Colorado University

Page 2: 600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western 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)

Page 3: 600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University

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?

Page 4: 600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University

Homework 5

http://wiki.western.edu/mcis/index.php/429/Week_5

Page 5: 600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University

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!

Page 6: 600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University

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)

Page 7: 600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University

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

Page 8: 600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University

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?

Page 9: 600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University

Questions?

Page 10: 600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University

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 “.”

Page 12: 600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University

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?