Skip to content

Commit

Permalink
Merge pull request #111 from serokell/gromak/#110-maintenance
Browse files Browse the repository at this point in the history
[#110] Maintenance
  • Loading branch information
gromakovsky authored Oct 23, 2019
2 parents 1b8905f + 5ff6713 commit b114726
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 157 deletions.
28 changes: 21 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ matrix:

include:

- ghc: 8.0.2
env: STACK_YAML="$HOME/build/serokell/o-clock/stack-8.0.2.yaml"
- ghc: 8.4.4
env: STACK_YAML="$HOME/build/serokell/o-clock/stack-8.4.4.yaml"
os: linux
addons:
apt:
packages:
- libgmp-dev

- ghc: 8.2.2
env: STACK_YAML="$HOME/build/serokell/o-clock/stack-8.2.2.yaml"
- ghc: 8.6.5
env: STACK_YAML="$HOME/build/serokell/o-clock/stack.yaml"
os: linux
addons:
apt:
packages:
- libgmp-dev

- ghc: 8.4.3
env: STACK_YAML="$HOME/build/serokell/o-clock/stack.yaml"
- ghc: 8.8.1
env: STACK_YAML="$HOME/build/serokell/o-clock/stack-8.8.1.yaml"
os: linux
addons:
apt:
Expand Down Expand Up @@ -61,6 +61,17 @@ matrix:
- ghc-8.6.1
- cabal-install-head

- ghc: 8.8.1
env: GHCVER='8.8.1' CABALVER='head'
os: linux
addons:
apt:
sources:
- hvr-ghc
packages:
- ghc-8.8.1
- cabal-install-head

install:
- |
if [ -z "$STACK_YAML" ]; then
Expand All @@ -83,7 +94,10 @@ script:
if [ -z "$STACK_YAML" ]; then
cabal new-test
else
stack build --test --bench --no-terminal --flag o-clock:aeson --flag o-clock:hashable --flag o-clock:serialise --flag o-clock:deepseq
stack build --test --no-terminal --flag o-clock:aeson --flag o-clock:hashable --flag o-clock:serialise --flag o-clock:deepseq
# We use kinda dead packages (tiempo and time-units) in benchmarks, so we have to use `allow-newer` to build them.
echo "allow-newer: true" >> $STACK_YAML
stack build --bench --no-terminal --flag o-clock:aeson --flag o-clock:hashable --flag o-clock:serialise --flag o-clock:deepseq --flag o-clock:bench-buildable
fi
notifications:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ Change log
o'clock uses [PVP Versioning][1].
The change log is available [on GitHub][2].

1.1.0
=====

* [#110](https://github.com/serokell/o-clock/issues/110):
Resurrect `o-clock` in nightly resolver. Specifically:
+ Explicitly support GHC-8.8.
+ Bump many upper bounds.
+ Make benchmarks not buildable by default.
+ Drop support for GHC-8.0 and GHC-8.2.

1.0.0.1
=======

Expand Down
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ Since this tutorial is literate haskell file, let's first write some pragmas and

module Main where

#if ( __GLASGOW_HASKELL__ >= 804 )
import Time (type (*))
#endif
import Time ((:%), (-:-), Time, Hour, UnitName,floorUnit, hour, seriesF, toUnit)

```
Expand All @@ -99,18 +97,10 @@ work day represented as `8` hours and work week represented as `5` work days.

```haskell
-- | Time unit for a working day (8 hours).
#if ( __GLASGOW_HASKELL__ >= 804 )
type WorkDay = 8 * Hour
#else
type WorkDay = 28800 :% 1
#endif

-- | Time unit for a work week (5 working days).
#if ( __GLASGOW_HASKELL__ >= 804 )
type WorkWeek = 5 * WorkDay
#else
type WorkWeek = 144000 :% 1
#endif

-- this allows to use 'Show' and 'Read' functions for our time units
type instance UnitName (28800 :% 1) = "wd" -- One WorkDay contains 28800 seconds
Expand Down
32 changes: 20 additions & 12 deletions o-clock.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: o-clock
version: 1.0.0.1
version: 1.1.0
synopsis: Type-safe time library.
description: See README.md for details.
homepage: https://github.com/serokell/o-clock
Expand All @@ -16,10 +16,11 @@ extra-doc-files: CHANGELOG.md
, README.md
, README.lhs
cabal-version: 2.0
tested-with: GHC == 8.0.2
, GHC == 8.2.2
, GHC == 8.4.3
tested-with: GHC == 8.4.3
, GHC == 8.4.4
, GHC == 8.6.1
, GHC == 8.6.5
, GHC == 8.8.1

source-repository head
type: git
Expand All @@ -46,13 +47,13 @@ library
, text
cpp-options: -DHAS_aeson
if flag(hashable)
build-depends: hashable >= 1.2.6 && < 1.3
build-depends: hashable >= 1.2.6 && < 1.4
cpp-options: -DHAS_hashable
if flag(deepseq)
build-depends: deepseq ^>= 1.4
cpp-options: -DHAS_deepseq
if flag(serialise)
build-depends: serialise >= 0.2
build-depends: serialise >= 0.2 && < 0.3
cpp-options: -DHAS_serialise

executable play-o-clock
Expand All @@ -76,11 +77,11 @@ test-suite o-clock-test

build-depends: base >= 4.9 && < 5
, o-clock
, hedgehog ^>= 0.6
, tasty >= 0.12 && < 1.2
, tasty-hedgehog >= 0.1 && < 0.3
, hedgehog >= 0.6 && < 1.1
, tasty >= 0.12 && < 1.3
, tasty-hedgehog >= 0.1 && < 1.1
, tasty-hspec ^>= 1.1.3
, type-spec ^>= 0.3.0.1
, type-spec >= 0.3.0.1 && < 0.5

ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010
Expand All @@ -95,7 +96,7 @@ test-suite o-clock-doctest
build-tool-depends: doctest:doctest
build-depends: base >= 4.10 && < 5
, doctest ^>= 0.16
, Glob ^>= 0.9
, Glob >= 0.9 && < 0.11
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010

Expand Down Expand Up @@ -125,6 +126,9 @@ benchmark o-clock-benchmark
build-depends: deepseq >= 1.4
cpp-options: -DNO_deepseq

if !flag(bench-buildable)
buildable: False

default-extensions: OverloadedStrings
RecordWildCards

Expand All @@ -144,4 +148,8 @@ flag deepseq

flag serialise
description: Provide instances for @serialise@
default: False
default: False

flag bench-buildable
description: Make benchmarks buildable
default: False
37 changes: 2 additions & 35 deletions src/Time/Rational.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,31 @@
module Time.Rational
( Rat (..)
, type (:%)
#if ( __GLASGOW_HASKELL__ >= 804 )
, type (%)
, type (*)
, type (/)
#endif
, MulK
, DivK
#if ( __GLASGOW_HASKELL__ >= 804 )
, Gcd
, Normalize
, DivRat
, type (>=%)
#endif

-- Utilities
, RatioNat
, KnownRat (..)

#if ( __GLASGOW_HASKELL__ >= 804 )
, withRuntimeDivRat
#endif
, KnownDivRat
) where

import Data.Kind (Type)
import Data.Proxy (Proxy (..))
import GHC.Natural (Natural)
import GHC.Real (Ratio ((:%)))

#if ( __GLASGOW_HASKELL__ >= 804 )
import GHC.TypeNats (Div, Mod, type (<=?))
#endif

#if ( __GLASGOW_HASKELL__ >= 802 )
import GHC.TypeNats (KnownNat, Nat, natVal)
#else
import GHC.TypeLits (KnownNat, Nat, natVal)
#endif

#if ( __GLASGOW_HASKELL__ >= 804 )
import Unsafe.Coerce (unsafeCoerce)
#endif

#if ( __GLASGOW_HASKELL__ >= 804 )
import GHC.TypeNats (Div, Mod, type (<=?), KnownNat, Nat, natVal)
import qualified GHC.TypeNats
#endif
import Unsafe.Coerce (unsafeCoerce)

-- | Data structure represents the rational number.
-- Rational number can be represented as a pair of
Expand All @@ -85,7 +64,6 @@ type instance DivK Rat Rat = Rat
type instance DivK Rat Nat = Rat
type instance DivK Nat Rat = Rat

#if ( __GLASGOW_HASKELL__ >= 804 )
-- | Overloaded multiplication.
type family (*) (a :: k1) (b :: k2) :: MulK k1 k2

Expand All @@ -101,12 +79,10 @@ type instance (a :: Nat) / (b :: Nat) = a % b
type instance (a :: Rat) / (b :: Rat) = DivRat a b
type instance (a :: Rat) / (b :: Nat) = DivRatNat a b
type instance (a :: Nat) / (b :: Rat) = DivRat (a :% 1) b
#endif

-- | More convenient name for promoted constructor of 'Rat'.
type (:%) = '(::%)

#if ( __GLASGOW_HASKELL__ >= 804 )
-- | Type family for normalized pair of 'Nat's — 'Rat'.
type family (m :: Nat) % (n :: Nat) :: Rat where
a % b = Normalize (a :% b)
Expand Down Expand Up @@ -213,7 +189,6 @@ infix 4 >=%
type family (m :: Rat) >=% (n :: Rat) :: Bool where
(a :% b) >=% (c :% d) = c * b <=? a * d

#endif

-- | Rational numbers, with numerator and denominator of 'Natural' type.
type RatioNat = Ratio Natural
Expand All @@ -223,13 +198,8 @@ class KnownRat (r :: Rat) where
ratVal :: RatioNat

instance (KnownNat a, KnownNat b) => KnownRat (a :% b) where
#if ( __GLASGOW_HASKELL__ >= 802 )
ratVal = natVal (Proxy @a) :% natVal (Proxy @b)
#else
ratVal = fromIntegral (natVal (Proxy @a)) :% fromIntegral (natVal (Proxy @b))
#endif

#if ( __GLASGOW_HASKELL__ >= 804 )
newtype KnownRatDict (unit :: Rat) r = MkKnownRatDict (KnownRat unit => r)

giftRat :: forall (unit :: Rat) r . (KnownRat unit => r) -> RatioNat -> r
Expand All @@ -240,12 +210,9 @@ giftRat given = unsafeCoerce (MkKnownRatDict given :: KnownRatDict unit r)
withRuntimeDivRat :: forall (a :: Rat) (b :: Rat) r . (KnownRat a, KnownRat b) => (KnownRat (a / b) => r) -> r
withRuntimeDivRat r = giftRat @(a / b) r (ratVal @a / ratVal @b)
{-# INLINE withRuntimeDivRat #-}
#endif

-- | Constraint alias for 'DivRat' units.
type KnownDivRat a b = ( KnownRat a
, KnownRat b
#if ( __GLASGOW_HASKELL__ >= 804 )
, KnownRat (a / b)
#endif
)
Loading

0 comments on commit b114726

Please sign in to comment.