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

About Lemmas and other questions #99

Open
hafizhmakmur opened this issue Jun 7, 2020 · 2 comments
Open

About Lemmas and other questions #99

hafizhmakmur opened this issue Jun 7, 2020 · 2 comments

Comments

@hafizhmakmur
Copy link

I find myself unable to understand how to use lemmas as is explained in Chapter 10. Is there any other illustrative example available to show how to use it? Do I really need to delve deep into the mathematical proof to understand it? Also Chapter 10 page is completely uncompilable because there are some missing imports that can't be fixed by user because the editor also don't recognize import.

In chapter 8 there is a code {-@ go :: UList a -> xs:[a] -> UList a / [len xs] @-} in nub. What does / here means? I found no other uses of it in Haskell except as a dividing operator, which I don't think is used here that way. I also can delete / [len xs] and it will still compile well. But I'm afraid that it turns out to be an important component to solve some problems. Also I don't really understand what ok in matFromList is supposed to do. What is the condition so that the input list can be rejected entirely? Is the tail supposed to be ignored like implied in xss@(xs:_)? Because the implementation that I have thought needs to use tail xss eventually.

In Chapter 12 there are two "Exercise: (Insertion):". Maybe the second one should be "Exercise: (Deletion):"? Also In Figure 12.5 The most left triangle should be 'll' instead of 'lr'. Also there are a lot of "--FIX ME" in the last exercises. Is it intended and is the content an "answer key" for the undefined measure? And what is the difference between inline and measure?

Also I find that the error messages when dealing with set measures can be really incomprehensible, especially compared to errors only related to lists. I wonder how it can be done better....

@ranjitjhala
Copy link
Member

ranjitjhala commented Jun 16, 2020 via email

@hafizhmakmur
Copy link
Author

Thank you very much! That blog is a very invaluable resource that I can ever find for this tutorial. Right now I'm skimming those articles to augment my understanding of LH. I think Abstract and Bounded Refinement Types would made a very good tutorial for next chapters.

For now I think I've found in that blog the solution for most of the problems I ask in prior question just like problem about inline, about aforementioned termination metrics, etc. I also found a solution that works for matFromList for me but I am not able to figure out how to use this template

matFromList      :: [[a]] -> Maybe (Matrix a)
matFromList []   = Nothing
matFromList xss@(xs:_)
  | ok           = Just (M r c vs)
  | otherwise    = Nothing
  where
    r            = size xss
    c            = size xs
    ok           = undefined
    vs           = undefined

and instead just remake the function from zero resulting in this

{-@ matFromList      :: x:[[a]] 
                        -> Maybe (MatrixN a {size x} {sizeFirstIdx x}) @-}
matFromList      :: [[a]] -> Maybe (Matrix a)
matFromList []   = Nothing
matFromList [[]] = Nothing
matFromList [xs] = Just (M 1 (size xs) (vecFromList [vecFromList xs]))
matFromList (xs:xss) = case matFromList xss of
    Just (M row col elts) 
        | col == size xs -> Just (M (row+1) col (vecFromList xs `vCons` elts)) 
        | otherwise -> Nothing
    Nothing -> Nothing

which I think is more elegant for me, but I still like to know the intended solution using that template.

Unfortunately I am still stumped in the lemma problem, hence the 3 problems in Chapter 8 (range), Chapter 10 (fresh) and Chapter 12 (insertAPI & deleteAPI. member is solved because it's just modification of mem from Chapter 10) is still unsolved for me. Would you like to give me another hint or clue for these? I'd really like to be able to figure out the answer after all this time.

Once again thank you @ranjitjhala ! May your work prosper and this software be better and better.

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