Hydrogen Prelude.
hydrogen-prelude
about
A Prelude that exports much of the standard library (more then Prelude), without conflicts. If for example you were to import Prelude and Data.List or Data.Foldable you will run into ambiguous imports (regarding foldr for example). This Prelude aims at exporting the most general functions (in this case foldr from Data.Foldable).
It also pulls in some default packages like cereal for serialization and containers for data types like Map and Set. Every datatype exported by this Prelude comes with instances for Serialize.
Longs story short, instead of:
import Prelude hiding (
all, and, any, concat, concatMap, elem, foldl, foldl1, foldr, foldr1,
mapM, mapM_, maximum, minimum, notElem, or, product, sequence, sequence_, sum
)
import "base" Control.Monad hiding (
forM, forM_, mapM, mapM_, msum, sequence, sequence_
)
import Data.Foldable
import Data.Traversable
import Data.List hiding (
all, and, any, concat, concatMap, elem, find, foldl, foldl', foldl1, foldr, foldr1,
mapAccumL, mapAccumR, maximum, maximumBy, minimum, minimumBy, notElem, or, product, sum
)
it suffices to:
import Hydrogen.Prelude
goodies
Beyond existing functions from well-known standard packages, this prelude defines a few utilities (mostly aimed at unifying functionality across different packages, like containers and array).
(!) :: Has a ⇒ a → HasKey a → HasValue a
(!) is provided for several data types which associate a key and a value.
[(1, 'a'), (3, 'v')] ! 1 → 'a'
Instances are defined for
Eq k ⇒ [(k, v)]Ix i ⇒ Array i ewithHasKey → iOrd k ⇒ Map k vwithHasValue → vOrd k ⇒ MultiMap k vwithHasValue → [v]
(?) :: Container a ⇒ a → Contained a → Bool
Check whether the element on the right is contained in the collection on the left.
[1, 2, 4] ? 3 → False
Instances are defined for
Eq a ⇒ [a]Ord a ⇒ Set aEq a ⇒ Seq aOrd k ⇒ Map k vwithContained → kOrd k ⇒ MultiMap k vwithContained → k
tmap
A little bit like fmap but defined differently on some datatypes (applies e.g. to both components of a tuple).
tmap succ (3, 4) → (4, 5)
Instances are defined for
(a, a)(a, a, a)(a, a, a, a)[a]Seq aMap k vMultiMap k v
fmap vs map
Hydrogen Prelude exports fmap as map - the way it ought to be.
__ :: a
A handy shortcut for undefined.
FSharp's |> (which is flip ($))
Use it to pipe things from one function to the other, left to right:
head xs |> fromEnum |> show
safeHead :: a → [a] → a
The head of the list, or the default given as first argument.
safeHead x xs = maybe x head . listToMaybe
ShowBox :: forall a. (Show a) ⇒ a → ShowBox
Wrap anything that is showable (can be used to build heterogeneous lists).
.|, .&, .^ :: (a → Bool) → (a → Bool) → (a → Bool)
Combines predicates.
filter (isDigit .| isLetter)
type List a = [a]
A longhand for the type of lists, if you prefer this more wordy version.
class Default a
A class that provides the def function for default values for types. Instances of MonadPlus automatically have an instance where def = mzero.
Default instances for most primitive types are also provided.
class Apply a
Provides the *$* operator which is your all-purpose application operator. It does uncurrying (if you want to apply a tupel result of a function to a function that is curryied, works with tupels of up to 5 components) and also works with Applicative, i.e. it also does fmap . uncurry:
data Operator = Operator Value OperatorType Value
parseInfixOperation :: Parser (Value, OperatorType, Value)
... Operator *$* parseInfixOperation ...
re-exports
Hydrogen.Prelude
The Hydrogen Prelude offers you the functions and datatypes from these modules, all with one import:
from
basemodule Preludemodule Control.Applicativemodule Control.Arrowmodule Control.Monadmodule Data.Bitsmodule Data.Boolmodule Data.Charmodule Data.Complexmodule Data.Complexmodule Data.Dynamicmodule Data.Eithermodule Data.Fixedmodule Data.Functionmodule Data.Foldablemodule Data.Intmodule Data.Ixmodule Data.Listmodule Data.Maybemodule Data.Ordmodule Data.Ratiomodule Data.Stringmodule Data.Timemodule Data.Traversablemodule Data.Tuplemodule Data.Typeablemodule Data.Wordmodule Numericmodule Text.Printf
from
arraymodule Data.Array
from
cerealmodule Data.Serialize
from
containersData.Set,Data.Map, andData.Seq
from
hashablemodule Data.Hashable
form
hydrogen-multimapHydrogen.MultiMap
from
hydrogen-versionmodule Hydrogen.Version
from
regex-tdfamodule Text.Regex.TDFA
from
timemodule Data.Time
from
transformersmodule Data.Functor.Identitymodule Data.Functor.Reverse
from
uuidData.UUIDData.UUID.fromStringasuuidFromStringData.UUID.V4.nextRandomasrandomUUID
Hydrogen.Prelude.IO
from
basemodule Data.IORefmodule Control.Concurretmodule Control.Exceptionmodule System.IOmodule System.Timeout
from
strict- strict IO functions
hGetContents',getContents',readFile',interact'
- strict IO functions
Hydrogen.Prelude.System
from
basemodule System.CPUTimemodule System.Environmentmodule System.Exitmodule System.Info
from
directorymodule System.Directory
from
filepathmodule System.FilePath
from
processmodule System.Process
from
randommodule System.Random
Hydrogen.Prelude.Network
- from
networkmodule Network
FAQ
How is some of the magic accomplished?
Mostly with XTypeFamilies and XStandaloneDeriving.
So this works only with GHC?
Yes, for now at least.
What is hydrogen
https://www.youtube.com/watch?v=rbBX6aEzEz8