hazel
hazel copied to clipboard
list literals
List Literals are an integral part of any programming language. It's a particularly interesting problem in Hazel, given it's hole-driven programming paradigm. This project involved creating a new UHExp constructor called listlit, which would also end up replacing the already existing constructor listnil. This was done by having listlit take an opseq option type argument, which could then take None as an argument, thus simulating listnil.
I also added a new constructor ListLitZ, which handles the zipper cases pertaining to list literals. Most of its logic followed that of ParenthesizedZ, which handles the zipper case corresponding to Parenthesized.
Here are some examples:
-
Creating an empty list.
-
Constructing a list with single element.
-
Adding multiple elements to the list.
-
Creating an empty hole in the middle of the list.
-
Constructing a list within a list.
-
Deleting the nested list, which then makes the nested elements belong to the outer list.
-
Deleting the list, thus making the elements just a sequence of numbers.
- The empty list screenshot is actually showing a list with one element, a hole. We discussed empty lists as being
[]
where you can place your cursor in between the[
and]
. - The types aren't correct in any of the screenshots -- you seem to have implemented tuples, not lists:
-
[_]
should have typeList(?)
not?
-
[1]
should have typeList(Num)
notNum
-
[1, 2, 3]
should have typeList(Num)
notNum, Num, Num
-
[1, ?, 3]
should have typeList(Num)
notNum, ?, Num
, using the same logic that Hannah has been using for case -
[1, [4, 5], 3]
should not be well-typed (all elements of a list have to have the same type), i.e. it should have a hole around it saying that the element types are inconsistent -
[1, 4, 5, 3]
should have typeList(Num)
-
These are fundamental issues, so I will mark this draft again. I haven't yet looked at the code.
I made some changes and have pushed them. This is the progress so far.
@dash-mode is this ready to review?
@LutSa this needs a bunch of conflicts resolved, can you see about getting that done soon?
What kind of "conflicts"? Do you mean conflicts when merge into dev?
Yes. On the PR at the very bottom of the page you can see a long list of files with conflicts that need to be resolved: https://github.com/hazelgrove/hazel/pull/226.
- merge with
dev
- not working in pattern position
- error holes are displayed in wrong position in DHExp
- get the click behavior for inconsistent branches working correctly (use place_Before and of_z)
- error messages in cursor inspector for list elements in analytic position
- DHExp list literal spaces between elements
- merge with
dev
- list literals in patterns need to be fixed
- cons operation doesn't allow insertion of type-incorrect expressions in tail position
- list literal patterns in analytic position, e.g. due to a type annotation, not displaying error holes and some editing bugs -- also creates problems when trying to edit the scrutinee of a case expression
- possibly due to impossible syn bug, cast errors appear when a variable from a list pattern is operated on
also need to merge with dev
- Can't enter anything into list literal body here: http://hazel.org/build/list-literals/#fun%C2%A0%5B%5D%C2%A0%7B%3F%7D
- Can't enter scrutinee here: http://hazel.org/build/list-literals/#case%C2%A0%3F%0A%7C%C2%A0%5B1%2C%C2%A02.%5D%C2%A0%3D%3E%C2%A0%3F%0Aend
- Inconsistent element types in pattern not working (may need to wait until impossible syn fix is in): http://hazel.org/build/list-literals/#case%C2%A0%3F%0A%7C%C2%A0%5B1%2C%C2%A02.%5D%C2%A0%3D%3E%C2%A0%3F%0Aend
Hazel 3 now has list literals. Archiving this Hazel 2 PR. Thank you for the work on this, @dash-mode and @LutSa!