Domain Specific Languages
From doing these activities students will
- Reason about what type is inferred for underspecified ad-hoc polymorphic functions
- Consider what some of our "languages in the wild" would look like as other implementations
- Synthesize a design checklist for what language designers should ask themselves before starting
Warm-up activity - 15 min
Think - 5 min
The type Integer represents integer numbers with no max or min (unbounded).
Consider these two functions that operate over Integers toInteger :: (Integral a) => a -> Integer
and fromInteger :: (Num a) => Integer -> a.
Like the Num typeclass which defines methods like + and *,
the Integral typeclass defines methods like div (integer division)
and mod
We often use these two functions to convert values from one numeric type to another
(casting). E.g. (fromInteger (toInteger (3 :: Word8))) :: Word16
Casting a number to a type that is too small to hold it will cause it to overflow.
Similarly a number may underflow.
What type ascriptions (::'s)
could you add to the following haskell expression to make the expression evaluate to the number 32512.
The reference solution uses the types Int16 Word8 and Int32.
maxbound - ((fromInteger (toInteger maxBound)) + (fromInteger (toInteger minBound)))
(maxBound :: Int16) - ( ((fromInteger (toInteger (maxBound :: Word8))) :: Int16) + ( (fromInteger (toInteger (minBound :: Int32))) :: Int16))
Pair - 5 min
With a neighbor, discuss your answers. Please write both of your names and your answer on one sheet of paper
Share and Answer - 5 min
Pairs may volunteer a solution, and the reference solution will be given.
Please turn in your attendance papers.
To standalone or not to standalone; that is the design decision
Matthew will hand out edited copies of select "Programming Languages in the Wild"
hw entries. The student whose entries are chosen will be ambassadors for a group.
Entries are selected on the impression of what will foster rich discussion;
groups are assigned by Matthew based on language likeness in your submissions.
Groups and Roles
Groups
Python
- Jingqi Y (Ambassador)
- Yash S
- Alex H
- Kostas T
- entry
Javascript
- Mert E (Ambassador)
- Remmy C
- Jaclyn T
- entry
OCAML
- J.M. M (Ambassador)
- Jack K
- Jacob B
- entry
BASIC
- Matt T (Ambassador)
- Matthew H
- Nate B
- entry
Clojure
- Henri S (Ambassador)
- Charlie D
- Chris P
- entry
Julia
- Maddie S (Ambassador)
- Long T
- Byron P
- entry
Elixir
- Dana G (Ambassador)
- Patrick W
- David Z
- entry
TikZ
- Pi F (Ambassador)
- Harrison K
- Elif O
- entry
CMAKE
- Skye S (Ambassador)
- Jared C
- Jinghan X
- entry
Roles
Scribes
Managers
- Keep track of time
- Note open discussion questions you want to come back to the big group with
Ambassadors
- Begin by sharing your language with the rest of the group to give them an understanding of it
- Prepare to present your group's criteria for when a domain specific language makes sense
Small group discussion - 30 min
Take a few minutes to discuss what the language is and its features.
Answer the following discussion question that pertain to your language:
- If your language was general purpose, how would a Domain Specific Language capture its
essence (main functionality or use cases)? E.g. What values and primitive operations would you neccessarily expect? What values and primitive operations do you think are superflous?
- If your language is a Domain Specific Languge, what does it provide that necessitates it being a language instead of a library in a general purpose language? (Or do you think it should have been a library?)
- (optional bonus question if time) What benefits would your language get from being able to
call or be called by another general purpose language? What tradeoffs would have to be made?
Considering your answers above, synthesize a checklist or a flowchart detailing what initial design decisions a language designer should make before starting a domain specific language.
Specifically, your flowchart should help a language designer answer either of these questions:
- In designing a language, how do I limit it to what is essential?
- How do I decide whether to build a language or a library?
Large group discussion - 15min
Ambassadors will take turns discussing their group's design process before
opening the floor to the rest of the class.
Cool-down activity - 10 min
All scribes will be tasked with commiting their group's design process to the
Reading Wiki. The head scribe will be in charge of combining the
results into an organized and focused entry for reference in future discussion.
All managers will get together and make tickets for the course.
Especially any noted questions that remained unanswered during the class.
All ambassadors will get together with Matthew and Kathleen and discuss how they think
the day went, how they think the pacing went, what they are looking forward to, any
worries they might have about the class, etc.
Class Dismissed
- Read Template Haskell paper for Monday and answer the questions