-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9646399
Showing
4 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
env: | ||
- ghc=7.6.1 cabal=1.18 | ||
- ghc=7.8.1 cabal=1.18 | ||
- ghc=7.10.1 cabal=1.22 benchmarks=1 tests=1 | ||
|
||
install: | ||
# Set up the Shell to treat the semicolon as && | ||
- set -o pipefail && set -e | ||
# Install GHC and Cabal | ||
- | ||
ghc=${ghc=7.10.1}; | ||
cabal=${cabal=1.22}; | ||
travis_retry sudo add-apt-repository -y ppa:hvr/ghc; | ||
travis_retry sudo apt-get update; | ||
travis_retry sudo apt-get install cabal-install-$cabal ghc-$ghc; | ||
export PATH=/opt/ghc/$ghc/bin:/opt/cabal/$cabal/bin:$PATH; | ||
# Update the Cabal database | ||
- cabal update | ||
# Switch to the distro: | ||
- | ||
export pkg_name=$(cabal info . | awk '{print $2;exit}'); | ||
cabal sdist; | ||
cd dist; | ||
tar xzvf $pkg_name.tar.gz; | ||
cd $pkg_name; | ||
# Install the lower bound dependencies | ||
- | ||
if [ "$lower_bound_dependencies" = "1" ]; | ||
then | ||
constraint_options=( | ||
); | ||
fi; | ||
# Install the library dependencies | ||
- cabal install --only-dependencies --reorder-goals --force-reinstalls | ||
${constraint_options[@]} | ||
$([ "$tests" = "1" ] && echo "--enable-tests") | ||
$([ "$benchmarks" = "1" ] && echo "--enable-benchmarks") | ||
# Build the library | ||
- cabal build | ||
# Configure and build the remaining stuff | ||
- cabal configure | ||
$([ "$tests" = "1" ] && echo "--enable-tests") | ||
$([ "$benchmarks" = "1" ] && echo "--enable-benchmarks") | ||
-f doctest | ||
- cabal build | ||
|
||
script: | ||
- | | ||
if [ "$tests" = "1" ]; | ||
then | ||
cabal clean; | ||
cabal test --show-details=always; | ||
fi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2016, Nikita Volkov | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: | ||
deque | ||
version: | ||
0.1 | ||
synopsis: | ||
|
||
homepage: | ||
https://github.com/nikita-volkov/deque | ||
bug-reports: | ||
https://github.com/nikita-volkov/deque/issues | ||
author: | ||
Nikita Volkov <nikita.y.volkov@mail.ru> | ||
maintainer: | ||
Nikita Volkov <nikita.y.volkov@mail.ru> | ||
copyright: | ||
(c) 2016, Nikita Volkov | ||
license: | ||
MIT | ||
license-file: | ||
LICENSE | ||
build-type: | ||
Simple | ||
cabal-version: | ||
>=1.10 | ||
|
||
|
||
source-repository head | ||
type: | ||
git | ||
location: | ||
git://github.com/nikita-volkov/deque.git | ||
|
||
|
||
library | ||
hs-source-dirs: | ||
library | ||
default-extensions: | ||
Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFunctor, DeriveGeneric, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, ImpredicativeTypes, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, PolyKinds, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples | ||
default-language: | ||
Haskell2010 | ||
other-modules: | ||
|
||
exposed-modules: | ||
Deque | ||
build-depends: | ||
base-prelude < 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module Deque where | ||
|
||
import BasePrelude hiding (uncons, unsnoc, cons, snoc) | ||
|
||
|
||
data Deque a = | ||
Deque ![a] ![a] | ||
|
||
shiftRight :: Deque a -> Deque a | ||
shiftRight (Deque snocList consList) = | ||
case consList of | ||
head : tail -> | ||
Deque (head : snocList) tail | ||
_ -> | ||
case reverse snocList of | ||
head : tail -> | ||
Deque (head : []) tail | ||
_ -> | ||
Deque snocList consList | ||
|
||
shiftLeft :: Deque a -> Deque a | ||
shiftLeft deque = | ||
fromMaybe deque $ | ||
fmap (\(a, b) -> cons a b) $ | ||
unsnoc deque | ||
|
||
cons :: a -> Deque a -> Deque a | ||
cons a (Deque snocList consList) = | ||
Deque (snocList) (a : consList) | ||
|
||
snoc :: a -> Deque a -> Deque a | ||
snoc a (Deque snocList consList) = | ||
Deque (a : snocList) (consList) | ||
|
||
uncons :: Deque a -> Maybe (a, Deque a) | ||
uncons deque = | ||
unconsWithoutBalancing deque <|> | ||
unconsWithoutBalancing (shiftRight deque) | ||
|
||
unconsWithoutBalancing :: Deque a -> Maybe (a, Deque a) | ||
unconsWithoutBalancing (Deque snocList consList) = | ||
case consList of | ||
head : tail -> | ||
Just (head, Deque snocList tail) | ||
_ -> | ||
Nothing | ||
|
||
unsnoc :: Deque a -> Maybe (a, Deque a) | ||
unsnoc (Deque snocList consList) = | ||
case snocList of | ||
head : tail -> | ||
Just (head, Deque tail consList) | ||
_ -> | ||
case reverse consList of | ||
head : tail -> | ||
Just (head, Deque tail []) | ||
_ -> | ||
Nothing |