packages feed

fib (empty) → 0.1

raw patch · 6 files changed

+167/−0 lines, 6 filesdep +base-nopreludedep +integer-gmpdep +semirings

Dependencies added: base-noprelude, integer-gmp, semirings

Files

+ CHANGELOG.md view
@@ -0,0 +1,12 @@+# Changelog++`fib` uses [PVP Versioning][1].+The changelog is available [on GitHub][2].++0.0.0+=====++* Initially created.++[1]: https://pvp.haskell.org+[2]: https://github.com/chessai/fib/releases
+ LICENSE view
@@ -0,0 +1,29 @@+BSD 3-Clause License++Copyright (c) 2019, chessai+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++* Redistributions of source code must retain the above copyright notice, this+  list of conditions and the following disclaimer.++* Redistributions in binary form must reproduce the above copyright notice,+  this list of conditions and the following disclaimer in the documentation+  and/or other materials provided with the distribution.++* Neither the name of the copyright holder nor the names of its+  contributors may be used to endorse or promote products derived from+  this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,6 @@+# fib++[![Hackage](https://img.shields.io/hackage/v/fib.svg)](https://hackage.haskell.org/package/fib)+[![BSD3 license](https://img.shields.io/badge/license-BSD3-blue.svg)](LICENSE)++fibonacci algebra
+ fib.cabal view
@@ -0,0 +1,54 @@+cabal-version: 2.4+name:+  fib+version:+  0.1+synopsis:+  fibonacci algebra+description:+  fibonacci algebra+homepage:+  https://github.com/chessai/fib+bug-reports:+  https://github.com/chessai/fib/issues+license:+  BSD-3-Clause+license-file:+  LICENSE+author:+  chessai+maintainer:+  chessai <chessai1996@gmail.com>+copyright:+  2019 chessai+category:+  Math+build-type:+  Simple+extra-doc-files:+    README.md+  , CHANGELOG.md+tested-with:+    GHC == 8.2.2+  , GHC == 8.4.4+  , GHC == 8.6.3++library+  hs-source-dirs:+    src+  exposed-modules:+    Fib+  other-modules:+    Prelude+  build-depends:+    , base-noprelude >= 4.10.1.0 && < 4.13+    , semirings >= 0.3+    , integer-gmp+  ghc-options:+    -Wall+  default-language:+    Haskell2010++source-repository head+  type:                git+  location:            https://github.com/chessai/fib.git
+ src/Fib.hs view
@@ -0,0 +1,51 @@+{-# language BangPatterns #-}+{-# language DeriveFoldable #-}+{-# language DeriveFunctor #-}+{-# language DeriveTraversable #-}+{-# language DerivingStrategies #-}++module Fib+  ( Fib(..)+  , phi+  , fib+  ) where++data Fib a = Fib a a+  deriving stock (Show)+  deriving stock (Functor,Foldable,Traversable)++instance Semiring a => Semiring (Fib a) where+  zero = Fib zero zero+  Fib a b `plus` Fib c d = Fib (a `plus` c) (b `plus` d)+  one = Fib one zero+  Fib a b `times` Fib c d = Fib (a `times` (c `plus` d) `plus` b `times` c) (a `times` c `plus` b `times` d)+  {-# inline zero #-}+  {-# inline one #-}+  {-# inline plus #-}+  {-# inline times #-}++instance Ring a => Ring (Fib a) where+  negate (Fib a b) = Fib (negate a) (negate b)+  {-# inline negate #-}++instance Applicative Fib where+  pure x = Fib x x+  {-# inline pure #-} +  Fib fa fb <*> Fib a b = Fib (fa a) (fb b)+  {-# inline (<*>) #-}++instance Monad Fib where+  Fib a b >>= f = Fib a' b' where+    Fib a' _ = f a+    Fib _ b' = f b+  {-# inline (>>=) #-}++phi :: Semiring a => Fib a+phi = one+{-# inline phi #-}++fib :: Ring a => Integer -> a+fib n+  | n >= 0 = case (phi ^ n) of (Fib a _) -> a+  | otherwise = case (Fib one (negate one) ^ negate n) of (Fib a _) -> a+{-# inlinable fib #-}
+ src/Prelude.hs view
@@ -0,0 +1,15 @@+module Prelude+  ( module P+  ) where++import GHC.Show as P (Show)+import Data.Eq as P (Eq(..))+import Data.Functor as P (Functor(..))+import Data.Foldable as P (Foldable(..))+import Data.Traversable as P (Traversable(..))+import Data.Semiring as P (Semiring(..),Ring(..),(+),(*),(-),(^))+import Control.Applicative as P (Applicative(..))+import Control.Monad as P (Monad(..))+import GHC.Integer as P (Integer)+import Data.Ord as P (Ord(..))+import Data.Bool as P (otherwise,Bool)