Skip to content
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

Syntax of refinement types #110

Open
jllang opened this issue Jul 13, 2021 · 4 comments
Open

Syntax of refinement types #110

jllang opened this issue Jul 13, 2021 · 4 comments

Comments

@jllang
Copy link

jllang commented Jul 13, 2021

I've read through the chapters 1 to 7 and haven't come accross a definition of the syntax of refinement types. I was expecting to see it rather early in the book. A BNF would be helpful. It seems that sometimes the same condition needs to be formulated differently in Haskell and LiquidHaskell. Mixing up Haskell and LiquidHaskell syntax seems to lead into often quite cryptic errors.

@ranjitjhala
Copy link
Member

ranjitjhala commented Jul 13, 2021 via email

@jllang
Copy link
Author

jllang commented Jul 13, 2021

Apparently, things like lambda terms and infix notation with backticks don't work with refinement types. This example is quite contrived but I think it makes my point clear: The type of lists of odd integers can be expressed as follows:
{-@ type ListOdd = {xs : [Int] | filter odd xs == xs} @-}
As filter takes two arguments, the expression
filter odd xs == xs
should be the same as
odd `filter` xs == xs
but if I try to write
{-@ type ListOdd = {xs : [Int] | odd `filter` xs == xs} @-}
I get the error saying

~/liquidhaskell-tutorial/src/Tutorial_08_Measure_Set.lhs:658:24: error:
    • Cannot parse specification:
    unexpected ":"
    expecting operator, white space or "}"
    • 
    |
658 | {-@ type ListOdd = {xs : [Int] | odd `filter` xs == xs} @-}
    |                        ^

The error message makes it look like as if the problem was with the colon while in reality the cause was the use of backticks. Of course, using filter as an infix function like this would be weird, but I think you get my point.

@jllang
Copy link
Author

jllang commented Jul 13, 2021

I think that a chapter listing some common error types along with explanations would be very valuable to beginners like me.

@jllang
Copy link
Author

jllang commented Jul 13, 2021

I take it that the backticks are not supported by the refinement type syntax. A beginner might be tempted to try to use them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants