Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12] Remove liquid haskell #24

Merged
merged 1 commit into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 (!!)