Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upFurther thoughts on the mandatory type annotation for lists #18
Comments
This comment has been minimized.
This comment has been minimized.
|
Yeah, I think it's a good idea to only make the type annotation required for empty lists There are a couple of minor details, but I don't think they are a big deal:
|
This comment has been minimized.
This comment has been minimized.
|
Ah, I get why you wouldn’t want |
This comment has been minimized.
This comment has been minimized.
|
The other reason that I avoid NonEmpty a = { xs : List a | 1 <= length xs }In fact, when I was adding Optional a = { xs : List a | length xs <= 1 }This is one of the reasons that The reason I decided against it in the end was because Dhall has a pretty consistent "no subtyping" rule because subtyping makes the language harder to teach to new users and refinement types are one form of subtyping. However, a more expert-friendly fork of Dhall could add something like this to the language. |
Profpatsch commentedJan 23, 2017
•
edited
It might improve write-ability of lists if the user only had to specify the type for empty list literals.
I know that it’s in the syntax parser atm, but it might make sense to move it to the inference algorithm.
Another idea:
In practice, non-empty lists are probably used a lot more than normal lists?
So how about changing the literal to be a non-empty list by default? Lists could then be defined as non-empty +
niland the annotation problem is gone (I hope). It also mirrors the “Monoid is a semigroup with zero element” structure better.In practice users would probably use
Maybe []for the “may be empty” case.Actually I really like that idea.