-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add list literal syntax #119
Conversation
Hi @EmilySillars I am still getting this error: |
Hi Max, Thank you for your comment and apologies on the late reply -- Lowering Stage:
The function lowerExpr inside lowerAst.hs has the type signature Current Compiler Error: You need to add a case to LowerExpr that transforms a ListExpr instance of A.Expr into an App instance of I.Expr.
How to do this??? Here is an exercise to get you started thinking about this. Exercise:
I'm writing up a worked example + solution for a similar exercise, and will post that here as soon as I'm finished with it. |
Here is an example of a similar exercise with solutions: |
Hi @j-hui ,
|
I believe Max's |
Hi Max,
You will likely need to import Data.Generics for this to work. This change allows you to bypass matching on all the different instance of an Expr when you only care about the ListExpr instance - it uses generics from a haskell library called SYBP.
After you complete these steps I will take a final pass over your code for style/ other nits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great Work, Max!
- I added some final nits.
EDITED:
In the interest of time, just fix the nits, don't worry about adding additional test cases!
- Could you also add two more list test cases, one that is for list of lists, and one that is for lists of tuples?
Something like printing outx
, wherex
is[[57,56,55],[54]]
and printing outy
, wherey
is[(57,57),(52,53)]
?
You will need to change the definition of List from being integer specific to being polymorphic:
type List a
Cons a (List a)
Nil
For printing the lists of lists, I would add another function
puts2DList cout lst = ...
and for printing a list of tuples, I would add two functions,
putsTuple cout tup = ... // prints out a tuple
putsListOfTuples cout lst = ...
// ^ where this func calls putsTuple for a single elt,
// ^ and calls putsListOfTuples (recurses) on rest of list
Adding these two cases shouldn't take too long. Message me if you get stuck.
src/Front/DesugarLists.hs
Outdated
helper [] = (Id nil) | ||
helper (h:t) = Apply (Apply (Id cons) h) (helper t) | ||
desugarExpr e = e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add newline!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
No description provided.