agda / agda2hs

Compiling Agda code to readable Haskell

Home Page:https://agda.github.io/agda2hs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Erroneous assumption about lambda precedence in generated code

bwbush opened this issue · comments

Code like

instance
  iMaybeHashable : ⦃ i : Hashable a ⦄  Hashable (Maybe a)
  iMaybeHashable {{_}} .hash Nothing = MakeHash ∘ hashBytes $ hash iUnitHashable tt
  iMaybeHashable {{i}} .hash (Just x) = MakeHash ∘ hashBytes $ hash iPairHashable (tt , x)
{-# COMPILE AGDA2HS iMaybeHashable #-}

becomes the uncompilable

instance (Hashable a) => Hashable (Maybe a) where
    hash Nothing = MakeHash . \ r -> hashBytes r $ hash ()
    hash (Just x) = MakeHash . \ r -> hashBytes r $ hash ((), x)

instead of the correct

instance (Hashable a) => Hashable (Maybe a) where
    hash Nothing = MakeHash . (\ r -> hashBytes r) $ hash ()
    hash (Just x) = MakeHash . (\ r -> hashBytes r) $ hash ((), x)

Our current pretty-printing library is not very consistent with parenthesis, @flupe has suggested we change to ghc-src-gen: #274