Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
148
Issues
148
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
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
purescript-gargantext
Commits
4127580b
Commit
4127580b
authored
Jul 17, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FIXME] overlapping instance compiles but RangeError: Maximum call stack size exceeded at runtime
parent
5cff20a1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
11 deletions
+42
-11
Crypto.purs
src/Gargantext/Utils/Crypto.purs
+42
-11
No files found.
src/Gargantext/Utils/Crypto.purs
View file @
4127580b
module Gargantext.Utils.Crypto where
import Data.Ord
import Data.Eq
import Data.Functor
import Data.Semigroup
import Data.Set (Set)
import Data.Set as Set
import Data.Array as Array
import Gargantext.Prelude
import Crypto.Simple as Crypto
-- | TODO use newtype to disambiguate Set String and Set Hash
-- Set String needs Set.map hash
-- Set Hash does not need Set.map hash (just concat)
type Hash = String
hash' :: forall a. Crypto.Hashable a => a -> String
hash' = Crypto.toString <<< Crypto.hash Crypto.SHA256
-- | Main exposed api
hash :: forall a. IsHashable a => a -> String
hash = toString <<< hash''
-- | Newtype HashDone is needed to disambiguate Set String and Set HashDone
-- Set String needs Set.map hash
-- Set HashDone does not need Set.map hash (just concat)
newtype HashDone = HashDone Hash
toString :: HashDone -> Hash
toString (HashDone x) = x
instance ordHashDone :: Ord HashDone where
compare (HashDone a) (HashDone b) = compare a b
instance eqHashDone :: Eq HashDone where
eq (HashDone a) (HashDone b) = eq a b
------------------------------------------------------------------------
hash' :: forall a. Crypto.Hashable a => a -> HashDone
hash' = HashDone <<< Crypto.toString <<< Crypto.hash Crypto.SHA256
class IsHashable a where
hash
:: a -> Hash
hash
'' :: a -> HashDone
instance isHashableString :: IsHashable String
where
hash = hash'
hash
''
= hash'
instance isHashableArray :: (Crypto.Hashable a, IsHashable a) => IsHashable (Array a)
------------------------------------------------------------------------
instance isHashableArrayHashDone :: IsHashable (Array HashDone)
where
hash = hash <<< Set.fromFoldable <<< map hash
hash'' = hash'' <<< Set.fromFoldable
else instance isHashableArray :: (Crypto.Hashable a, IsHashable a) => IsHashable (Array a)
where
hash'' = hash'' <<< map hash
instance isHashableSet :: IsHashable (Set String) where
hash = hash <<< concat <<< toArray
------------------------------------------------------------------------
instance isHashableSetHashDone :: IsHashable (Set HashDone) where
hash'' = hash'' <<< concat <<< map toString <<< toArray
where
toArray :: forall a. Set a -> Array a
toArray = Set.toUnfoldable
concat :: Array Hash -> String
concat = Array.foldl (<>) ""
else instance isHashableSet :: (Crypto.Hashable a, IsHashable a) => IsHashable (Set a)
where
hash'' = hash'' <<< Set.map hash''
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