hazel icon indicating copy to clipboard operation
hazel copied to clipboard

list literals

Open dash-mode opened this issue 4 years ago • 11 comments

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. Screenshot 2020-05-03 at 12 20 44 PM

  • Constructing a list with single element. Screenshot 2020-05-03 at 12 20 58 PM

  • Adding multiple elements to the list. Screenshot 2020-05-03 at 12 21 15 PM

  • Creating an empty hole in the middle of the list. Screenshot 2020-05-03 at 12 21 27 PM

  • Constructing a list within a list. Screenshot 2020-05-03 at 12 21 41 PM

  • Deleting the nested list, which then makes the nested elements belong to the outer list. Screenshot 2020-05-03 at 12 21 54 PM

  • Deleting the list, thus making the elements just a sequence of numbers. Screenshot 2020-05-03 at 12 22 07 PM

dash-mode avatar May 03 '20 16:05 dash-mode

  • 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 type List(?) not ?
    • [1] should have type List(Num) not Num
    • [1, 2, 3] should have type List(Num) not Num, Num, Num
    • [1, ?, 3] should have type List(Num) not Num, ?, 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 type List(Num)

These are fundamental issues, so I will mark this draft again. I haven't yet looked at the code.

cyrus- avatar May 03 '20 18:05 cyrus-

I made some changes and have pushed them. This is the progress so far.

  • Screenshot 2020-05-04 at 3 37 09 PM
  • Screenshot 2020-05-04 at 3 37 21 PM
  • Screenshot 2020-05-04 at 3 37 34 PM

dash-mode avatar May 04 '20 19:05 dash-mode

@dash-mode is this ready to review?

cyrus- avatar Jun 08 '20 06:06 cyrus-

@LutSa this needs a bunch of conflicts resolved, can you see about getting that done soon?

cyrus- avatar Jun 15 '22 20:06 cyrus-

What kind of "conflicts"? Do you mean conflicts when merge into dev?

LutSa avatar Jun 15 '22 21:06 LutSa

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.

cyrus- avatar Jun 15 '22 21:06 cyrus-

  • 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

cyrus- avatar Jun 29 '22 18:06 cyrus-

  • merge with dev
  • list literals in patterns need to be fixed
  • cons operation doesn't allow insertion of type-incorrect expressions in tail position

cyrus- avatar Jul 08 '22 19:07 cyrus-

  • 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

cyrus- avatar Jul 18 '22 20:07 cyrus-

also need to merge with dev

cyrus- avatar Jul 18 '22 20:07 cyrus-

  • 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

cyrus- avatar Aug 05 '22 19:08 cyrus-

Hazel 3 now has list literals. Archiving this Hazel 2 PR. Thank you for the work on this, @dash-mode and @LutSa!

cyrus- avatar Sep 30 '22 04:09 cyrus-