Skip to content

Commit

Permalink
[#12] Remove liquid haskell (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
vrom911 authored and chshersh committed Jul 19, 2018
1 parent e4972c7 commit 4425445
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 41 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -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].
Expand Down
4 changes: 1 addition & 3 deletions README.md
Expand Up @@ -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?
------------------------
Expand Down
62 changes: 30 additions & 32 deletions 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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
14 changes: 9 additions & 5 deletions 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
Expand Down Expand Up @@ -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 (!!)

0 comments on commit 4425445

Please sign in to comment.