liquid-haskell

Can I define parametric data type where parameters are not equals between in Haskell?

雨燕双飞 提交于 2019-12-10 22:59:38
问题 Problem: Let's imagine we have a Passenger with start and end points represented by: data Passenger a = Passenger { start :: a , end :: a } Question: How can I apply a class constraints to Passenger, where the start point shouldn't be equal to the end point? P.S.: I have asked a similar question in the Scala community, but I didn't receive any answer. Considering that refined library for scala is inspired by refined for Haskell, also hearing about liquid-Haskell, I wonder how can resolve it

How to write a log2 function in Liquid Haskell

China☆狼群 提交于 2019-12-10 19:28:13
问题 I am trying to learn Liquid Haskell from the book. To test my understanding, I wanted to write a function log2 which takes an input of the form 2^n and outputs n. I have the following code: powers :: [Int] powers = map (2^) [0..] {-@ type Powers = {v:Nat | v elem powers } @-} {-@ log2 :: Powers -> Nat @-} log2 :: Int -> Int log2 n | n == 1 = 0 | otherwise = 1 + log2 (div n 2) But some strange error occurs while executing this code, namely "Sort Error in Refinement". I am unable to understand

What is the correct contract of the function “map” in Liquid Haskell?

南笙酒味 提交于 2019-12-10 12:54:40
问题 I am trying to solve some exercise from LiquidHaskell tutorial. So, I wrote this: data List a = Nil | Cons a (List a) deriving (Show) infixr 5 `Cons` {-@ len :: List a -> Nat @-} len :: List a -> Int len Nil = 0 len (x `Cons` xs) = 1 + len xs {-@ mymap :: (a -> b) -> xs : List a -> { ys : List b | len xs == len ys } @-} mymap :: (a -> b) -> List a -> List b mymap _ Nil = Nil mymap f (x `Cons` xs) = f x `Cons` mymap f xs But I'm getting an error (excuse, pls, this formatting, it's the original