LiquidHaskell: attempting to use the take keyword, but the data type is not numeric

I am trying to write some specifications for a module Data.Ratio. So far I:

module spec Data.Ratio where

import GHC.Real

Data.Ratio.denominator :: GHC.Real.Integral a => r : GHC.Real.Ratio a -> {x:a | x > 0}

The code I'm checking is:

{-@ die :: {v:String | false} -> a @-}
die msg = error msg

main :: IO ()
main = do
  let x = 3 % 5
  print $ denominator x
  if denominator x < 0
    then die "bad ending"
    else putStrLn "good ending"

The code is considered safe because the denominator never returns a negative value.

I found this strange because I could just write x <= 0as a postcondition, which according to the module documentation is Data.Rationot possible. Obviously, Liquid Haskell does not compare my postcondition with the implementation denominator.

I understand that since the implementation of the function has not been tested, I better use the accept keyword:

assume Data.Ratio.denominator :: GHC.Real.Integral a => r : GHC.Real.Ratio a -> {x:a | x > 0}

However, I get:

Error: Bad Type Specification
 assumed type GHC.Real.denominator :: (Ratio a) -> {VV: a | VV> 0}
     Sort Error in Refinement: {VV : a_a2kc | VV > 0}
     Unbound Symbol a_a2kc
 Perhaps you meant: papp5, papp3, papp4, head, papp2, papp7, papp6, papp1, tail
  because
The sort a_a2kc is not numeric

  • LH assume , ?
  • , assume?
  • a ? , assume?
+4
1

, "Numeric" "Num" . LH , ; , !

, , , Int Integer, LH :

import GHC.Real

{-@ assume denom :: r:GHC.Real.Ratio Int -> {x:Int | x >= 0} @-}
denom :: GHC.Real.Ratio Int -> Int 
denom = denominator

{-@ die :: {v:String | false} -> a @-}
die msg = error msg

main :: IO ()
main = do
  let x = 3 % 5
  print $ denom x
  if denom x <= 0
    then die "bad ending"
    else putStrLn "good ending"

http://goto.ucsd.edu:8090/index.html#?demo=permalink%2F1504739852_3583.hs

x > 0, .

http://goto.ucsd.edu:8090/index.html#?demo=permalink%2F1504739907_3585.hs

Ratio!

0

Source: https://habr.com/ru/post/1682221/


All Articles