From 4425445a1a13005c1d34f4756c46d1a5a5b40aac Mon Sep 17 00:00:00 2001 From: Veronika Romashkina Date: Thu, 19 Jul 2018 17:13:43 +0800 Subject: [PATCH] [#12] Remove liquid haskell (#24) --- CHANGELOG.md | 3 +- README.md | 4 +-- src/Universum/Nub.hs | 62 ++++++++++++++++++++--------------------- src/Universum/Unsafe.hs | 14 ++++++---- 4 files changed, 42 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9acdfa4e..71205f32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ Change log * [#2](https://github.com/kowainik/universum/issues/2): Remove `microlens` from dependencies. - +* [#12](https://github.com/kowainik/universum/issues/12): + Remove `liquid-haskell` support. universum uses [PVP Versioning][1]. The change log is available [on GitHub][2]. diff --git a/README.md b/README.md index 80195712..ff125336 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,7 @@ Universum documenation regarding internal module structure. 2. `universum`-specific [HLint](http://hackage.haskell.org/package/hlint) rules: [`.hlint.yaml`](https://github.com/kowainik/universum/blob/master/.hlint.yaml) -3. Only a few LiquidHaskell properties right now, but LiquidHaskell is on Travis - CI and other properties are just waiting to be added! -4. Focus on safety, convenience and efficiency. +3. Focus on safety, convenience and efficiency. What is this file about? ------------------------ diff --git a/src/Universum/Nub.hs b/src/Universum/Nub.hs index 0a4d0be9..f8cb0a50 100644 --- a/src/Universum/Nub.hs +++ b/src/Universum/Nub.hs @@ -1,3 +1,10 @@ +{- +Copyright: (c) 2016 Stephen Diehl + (c) 20016-2018 Serokell + (c) 2018 Kowainik +License: MIT +-} + {-| Functions to remove duplicates from a list. = Performance @@ -32,30 +39,16 @@ import Data.Eq (Eq) import Data.Hashable (Hashable) import Data.HashSet as HashSet import Data.Ord (Ord) -import Data.Set (Set) -import Prelude (Bool, Char, (.)) +import Prelude ((.)) import qualified Data.Set as Set --- Liquid Haskell check for duplicates. -{-@ type ListUnique a = {v : [a] | NoDups v} @-} - -{-@ predicate NoDups L = Set_emp (dups L) @-} - -{-@ measure dups :: [a] -> (Set a) - dups ([]) = {v | Set_emp v} - dups (x:xs) = {v | v = - if (Set_mem x (listElts xs)) - then (Set_cup (Set_sng x) (dups xs)) - else (dups xs)} -@-} +{- | Like 'Prelude.nub' but runs in @O(n * log n)@ time and requires 'Ord'. -{-@ Set.toList :: Set a -> ListUnique a @-} +>>> ordNub [3, 3, 3, 2, 2, -1, 1] +[3,2,-1,1] --- | Like 'Prelude.nub' but runs in @O(n * log n)@ time and requires 'Ord'. --- --- >>> ordNub [3, 3, 3, 2, 2, -1, 1] --- [3,2,-1,1] +-} ordNub :: (Ord a) => [a] -> [a] ordNub = go Set.empty where @@ -65,10 +58,12 @@ ordNub = go Set.empty then go s xs else x : go (Set.insert x s) xs --- | Like 'Prelude.nub' but runs in @O(n * log_16(n))@ time and requires 'Hashable'. --- --- >>> hashNub [3, 3, 3, 2, 2, -1, 1] --- [3,2,-1,1] +{- | Like 'Prelude.nub' but runs in @O(n * log_16(n))@ time and requires 'Hashable'. + +>>> hashNub [3, 3, 3, 2, 2, -1, 1] +[3,2,-1,1] + +-} hashNub :: (Eq a, Hashable a) => [a] -> [a] hashNub = go HashSet.empty where @@ -78,17 +73,20 @@ hashNub = go HashSet.empty then go s xs else x : go (HashSet.insert x s) xs --- | Like 'ordNub' but also sorts a list. --- --- >>> sortNub [3, 3, 3, 2, 2, -1, 1] --- [-1,1,2,3] -{-@ sortNub :: [a] -> ListUnique a @-} +{- | Like 'ordNub' but also sorts a list. + +>>> sortNub [3, 3, 3, 2, 2, -1, 1] +[-1,1,2,3] + +-} sortNub :: (Ord a) => [a] -> [a] sortNub = Set.toList . Set.fromList --- | Like 'hashNub' but has better performance and also doesn't save the order. --- --- >>> unstableNub [3, 3, 3, 2, 2, -1, 1] --- [1,2,3,-1] +{- | Like 'hashNub' but has better performance and also doesn't save the order. + +>>> unstableNub [3, 3, 3, 2, 2, -1, 1] +[1,2,3,-1] + +-} unstableNub :: (Eq a, Hashable a) => [a] -> [a] unstableNub = HashSet.toList . HashSet.fromList diff --git a/src/Universum/Unsafe.hs b/src/Universum/Unsafe.hs index 7f111794..5f97c8f8 100644 --- a/src/Universum/Unsafe.hs +++ b/src/Universum/Unsafe.hs @@ -1,5 +1,12 @@ {-# LANGUAGE Unsafe #-} +{- +Copyright: (c) 2016 Stephen Diehl + (c) 20016-2018 Serokell + (c) 2018 Kowainik +License: MIT +-} + {- | Unsafe functions to work with lists and 'Maybe'. Sometimes unavoidable but better don't use them. This module is intended to be imported qualified and it's not even included @@ -28,11 +35,8 @@ import Data.List (head, init, last, tail, (!!)) import Data.Maybe (fromJust) import Universum.Base (Int) - --- Non empty list definition for @liquidhaskell@. -{-@ type NonEmptyList a = {xs : [a] | len xs > 0} @-} +import Universum.Function (flip) -- | Similar to '!!' but with flipped arguments. -{-@ at :: n : Nat -> {xs : NonEmptyList a | len xs > n} -> a @-} at :: Int -> [a] -> a -at n xs = xs !! n +at = flip (!!)