Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Przemyslaw Kaminski
haskell-gargantext
Commits
1888c343
Commit
1888c343
authored
Apr 23, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[RESEARCH] thx to Gabriel Gonzales work n Fibonacci.
parent
4abc2735
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
6 deletions
+60
-6
Prelude.hs
src/Gargantext/Prelude.hs
+0
-6
Fibonacci.hs
src/Gargantext/Prelude/Fibonacci.hs
+60
-0
No files found.
src/Gargantext/Prelude.hs
View file @
1888c343
...
...
@@ -297,12 +297,6 @@ ma :: [Double] -> [Double]
ma
=
movingAverage
3
-----------------------------------------------------------------------
fib
::
Int
->
Int
fib
0
=
0
fib
1
=
1
fib
n
=
fib
(
n
-
1
)
+
fib
(
n
-
2
)
-----------------------------------------------------------------------
--- Map in Map = Map2
-- To avoid Map (a,a) b
...
...
src/Gargantext/Prelude/Fibonacci.hs
0 → 100644
View file @
1888c343
{-|
Module : Gargantext.Prelude.Utils
Description : Useful Tools near Prelude of the project
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
Source:
Gabriel Gonzales, Blazing fast Fibonacci numbers using Monoids, 2020-04,
http://www.haskellforall.com/2020/04/blazing-fast-fibonacci-numbers-using.html
(This post illustrates a nifty application of Haskell’s standard library to solve a numeric problem.)
TODO: quikcheck
-}
module
Gargantext.Prelude.Fibonacci
where
import
qualified
Data.Semigroup
as
Semigroup
-------------------------------------------------------------
fib'
::
Integer
->
Integer
fib'
0
=
0
fib'
1
=
1
fib'
n
=
fib
(
n
-
1
)
+
fib
(
n
-
2
)
-------------------------------------------------------------
data
Matrix2x2
=
Matrix
{
x00
::
Integer
,
x01
::
Integer
,
x10
::
Integer
,
x11
::
Integer
}
instance
Monoid
Matrix2x2
where
mempty
=
Matrix
{
x00
=
1
,
x01
=
0
,
x10
=
0
,
x11
=
1
}
instance
Semigroup
Matrix2x2
where
Matrix
l00
l01
l10
l11
<>
Matrix
r00
r01
r10
r11
=
Matrix
{
x00
=
l00
*
r00
+
l01
*
r10
,
x01
=
l00
*
r01
+
l01
*
r11
,
x10
=
l10
*
r00
+
l11
*
r10
,
x11
=
l10
*
r01
+
l11
*
r11
}
fib
::
Integer
->
Integer
fib
n
=
x01
(
Semigroup
.
mtimesDefault
n
matrix
)
where
matrix
=
Matrix
{
x00
=
0
,
x01
=
1
,
x10
=
1
,
x11
=
1
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment