Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
145
Issues
145
List
Board
Labels
Milestones
Merge Requests
6
Merge Requests
6
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
gargantext
haskell-gargantext
Commits
817f7a43
Commit
817f7a43
authored
6 years ago
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] Syntactic convention (proposition to be discussed).
parent
5550fd5a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
12 deletions
+38
-12
Prelude.hs
src/Gargantext/Prelude.hs
+38
-12
No files found.
src/Gargantext/Prelude.hs
View file @
817f7a43
...
...
@@ -23,10 +23,11 @@ module Gargantext.Prelude
,
module
Text
.
Show
,
module
Text
.
Read
,
cs
,
module
Data
.
Maybe
)
where
import
Data.Maybe
(
isJust
,
fromJust
)
import
Data.Maybe
(
isJust
,
fromJust
,
maybe
)
import
Protolude
(
Bool
(
True
,
False
),
Int
,
Double
,
Integer
,
Fractional
,
Num
,
Maybe
(
Just
,
Nothing
)
,
Floating
,
Char
,
IO
...
...
@@ -34,14 +35,15 @@ import Protolude ( Bool(True, False), Int, Double, Integer
,
head
,
flip
,
Ord
,
Integral
,
Foldable
,
RealFrac
,
Monad
,
filter
,
reverse
,
map
,
zip
,
drop
,
take
,
zipWith
,
sum
,
fromIntegral
,
length
,
fmap
,
sum
,
fromIntegral
,
length
,
fmap
,
foldl
,
foldl'
,
takeWhile
,
sqrt
,
undefined
,
identity
,
abs
,
maximum
,
minimum
,
return
,
snd
,
truncate
,
(
+
),
(
*
),
(
/
),
(
-
),
(
.
),
(
$
),
(
**
),
(
^
),
(
<
),
(
>
)
,
Eq
,
(
==
),
(
>=
),
(
<=
),
(
<>
)
,
abs
,
m
in
,
max
,
m
aximum
,
minimum
,
return
,
snd
,
truncate
,
(
+
),
(
*
),
(
/
),
(
-
),
(
.
),
(
$
),
(
**
),
(
^
),
(
<
),
(
>
)
,
log
,
Eq
,
(
==
),
(
>=
),
(
<=
),
(
<>
)
,
(
/=
)
,
(
&&
),
(
||
),
not
,
fst
,
snd
,
toS
,
elem
,
elem
,
die
,
mod
,
div
,
curry
,
uncurry
)
-- TODO import functions optimized in Utils.Count
...
...
@@ -49,7 +51,10 @@ import Protolude ( Bool(True, False), Int, Double, Integer
-- import Gargantext.Utils.Count
import
qualified
Data.List
as
L
hiding
(
head
,
sum
)
import
qualified
Control.Monad
as
M
import
qualified
Data.Map
as
Map
import
Data.Map
(
Map
)
import
qualified
Data.Map
as
M
import
Data.Map.Strict
(
insertWith
)
import
qualified
Data.Vector
as
V
import
Safe
(
headMay
)
...
...
@@ -163,12 +168,12 @@ sumKahan = snd . L.foldl' go (0,0)
t'
=
t
+
y
-- | compute part of the dict
count2map
::
(
Ord
k
,
Foldable
t
)
=>
t
k
->
Map
.
Map
k
Double
count2map
xs
=
M
ap
.
map
(
/
(
fromIntegral
(
length
xs
)))
(
count2map'
xs
)
count2map
::
(
Ord
k
,
Foldable
t
)
=>
t
k
->
Map
k
Double
count2map
xs
=
M
.
map
(
/
(
fromIntegral
(
length
xs
)))
(
count2map'
xs
)
-- | insert in a dict
count2map'
::
(
Ord
k
,
Foldable
t
)
=>
t
k
->
Map
.
Map
k
Double
count2map'
xs
=
L
.
foldl'
(
\
x
y
->
insertWith
(
+
)
y
1
x
)
M
ap
.
empty
xs
count2map'
::
(
Ord
k
,
Foldable
t
)
=>
t
k
->
Map
k
Double
count2map'
xs
=
L
.
foldl'
(
\
x
y
->
insertWith
(
+
)
y
1
x
)
M
.
empty
xs
trunc
::
(
RealFrac
a
,
Integral
c
,
Integral
b
)
=>
b
->
a
->
c
...
...
@@ -227,6 +232,27 @@ zipSnd f xs = zip xs (f xs)
-- Just
unMaybe
::
[
Maybe
a
]
->
[
a
]
unMaybe
=
map
fromJust
.
L
.
filter
isJust
-- | Syntactic convention for the reader/writer coordination.
-- @Motivation@: explicit functional flux ease coordination between
-- readers and writers who are not always the same individuals. Each
-- natural languages has its own syntaxical conventions from left to
-- right or the contrary. In computer programming languages it depends
-- on context of the algorithm itself and we need some clarity since
-- both are possible, here is a proposition to get more explicitiness.
-- | (~>) is called : "rightLeft" as "from right to left". The most right
-- function sends its output to the most left function which takes it as
-- input.
(
<~
)
::
(
a
->
b
)
->
a
->
b
(
<~
)
=
(
$
)
-- | (<~) is called : "leftRight" as "from left to right". The most left
-- function sends its output to the most right function which takes it as
-- input.
(
~>
)
::
a
->
(
a
->
c
)
->
c
(
~>
)
=
flip
(
$
)
This diff is collapsed.
Click to expand it.
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