Prelude.purs 2.09 KB
Newer Older
1
module Gargantext.Prelude (module Prelude, logs, logExceptions, id, class Read, read, xor)
2 3
  where

4
import Data.Maybe (Maybe)
5
import Prelude (class Applicative, class Apply, class Bind, class BooleanAlgebra, class Bounded, class Category, class CommutativeRing, class Discard, class DivisionRing, class Eq, class EuclideanRing, class Field, class Functor, class HeytingAlgebra, class Monad, class Monoid, class Ord, class Ring, class Semigroup, class Semigroupoid, class Semiring, class Show, type (~>), Ordering(..), Unit, Void, absurd, add, ap, append, apply, between, bind, bottom, clamp, compare, comparing, compose, conj, const, degree, discard, disj, eq, flap, flip, gcd, identity, ifM, join, lcm, liftA1, liftM1, map, max, mempty, min, mod, mul, negate, not, notEq, one, otherwise, pure, recip, show, sub, top, unit, unless, unlessM, void, when, whenM, zero, (#), ($), ($>), (&&), (*), (*>), (+), (-), (/), (/=), (<), (<#>), (<$), (<$>), (<*), (<*>), (<<<), (<=), (<=<), (<>), (<@>), (=<<), (==), (>), (>=), (>=>), (>>=), (>>>), (||))
6
import Effect.Console (log)
7
import Effect.Class (class MonadEffect, liftEffect)
8 9
import Effect.Exception (catchException, throwException)
import Effect.Unsafe (unsafePerformEffect)
10

11 12 13 14 15 16 17 18
-- | JL: Astonishingly, not in the prelude
--   AD: recent Preludes in Haskell much prefer identity
--   then id can be used as a variable name (in records for instance)
--   since records in Purescript are not the same as in Haskell
--   this behavior is questionable indeed.
id :: forall a. a -> a
id a = a

19 20
class Read a where
  read :: String -> Maybe a
21

22
logs:: forall message effect.
23 24 25
       (MonadEffect effect)
       => Show message
       => message 
26 27 28
       -> effect Unit
logs = liftEffect <<< log <<< show

29 30 31 32 33 34 35 36
logExceptions :: forall message a b. Show message =>
                 message -> (a -> b) -> a -> b
logExceptions message f x =
  unsafePerformEffect $ do
    catchException (\e -> do logs message
                             logs e
                             throwException e) do
      pure $ f x
37

38 39 40 41
xor :: Boolean -> Boolean -> Boolean
xor true false = true
xor false true = true
xor _      _   = false