Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
541 views
in Technique[技术] by (71.8m points)

liquid haskell - Problem with naming record fields for List data type

For the sake of demonstration, I have two nearly-identical files: ListSuccess.hs and ListFailure.hs:

-- File: ListSuccess.hs
module ListSuccess where


import           Prelude                 hiding ( head
                                                , tail
                                                )


{-@
data List a = Nil | Cons { lh :: a , lt :: List a }
@-}
data List a = Nil |Cons { lh :: a , lt :: List a }
-- File: ListFailure.hs
module ListFailure where


import           Prelude                 hiding ( head
                                                , tail
                                                )


{-@
data List a = Nil | Cons { head :: a , tail :: List a }
@-}
data List a = Nil | Cons { head :: a , tail :: List a }

The only difference between these files is that ListSuccess names the fields of Cons as lh and lt, and ListFailure names the fields of Cons as head and tail.

Compiling with liquid, ListSuccess.hs compiles successfully, however ListFailure fails to compile, yielding this error:

 10 | data List a = Nil | Cons { head :: a , tail :: List a }
           ^^^^^

     ListFailure.head :: forall a .
                         lq$recSel:(ListFailure.List a) -> {VV : a | VV == head lq$recSel}
     Sort Error in Refinement: {VV : a##xo | VV == head lq$recSel}
     Cannot unify fix$36$$91$$93$ with ListFailure.List in expression: head lq$recSel


 /Users/henry/Documents/Prototypes/liquidhaskell/list-fields-bug/ListFailure.hs:12:21-55: Error: Illegal type specification for `ListFailure.Cons`

 12 | data List a = Nil | Cons { head :: a , tail :: List a }
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

     ListFailure.Cons :: forall a .
                         head:a -> tail:(ListFailure.List a) -> {VV : (ListFailure.List a) | tail VV == tail
                                                                                             && head VV == head}
     Sort Error in Refinement: {VV : (ListFailure.List a##agi) | (tail VV == tail##ListFailure.Cons
                                                                  && head VV == head##ListFailure.Cons)}
     Cannot unify fix$36$$91$$93$ with ListFailure.List in expression: tail VV

As far as I can tell, using head and tail as the field names should not be an issue, especially because I imported prelude hiding those names. The same error occurs even when I use import qualified Prelude and similar variants.

Is this a bug, or is there something that I'm missing here?

Configuration:

  • LiquidHaskell Version 0.8.6.0.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...