Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
quasar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
quasar
Commits
8b47674f
Commit
8b47674f
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Improve the prelude
Co-authored-by:
Jan Beinke
<
git@janbeinke.com
>
parent
fc85ec26
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
quasar.cabal
+3
-0
3 additions, 0 deletions
quasar.cabal
src/Quasar/Prelude.hs
+30
-13
30 additions, 13 deletions
src/Quasar/Prelude.hs
src/Quasar/PreludeExtras.hs
+22
-4
22 additions, 4 deletions
src/Quasar/PreludeExtras.hs
with
55 additions
and
17 deletions
quasar.cabal
+
3
−
0
View file @
8b47674f
...
...
@@ -15,6 +15,7 @@ common shared-properties
default-extensions:
AllowAmbiguousTypes
BangPatterns
ConstraintKinds
DataKinds
DefaultSignatures
DeriveAnyClass
...
...
@@ -33,6 +34,7 @@ common shared-properties
NamedFieldPuns
NoImplicitPrelude
OverloadedStrings
PolyKinds
RankNTypes
ScopedTypeVariables
StandaloneDeriving
...
...
@@ -48,6 +50,7 @@ common shared-properties
hashable,
microlens-platform,
mtl,
record-hasfield,
template-haskell,
transformers,
unordered-containers,
...
...
This diff is collapsed.
Click to expand it.
src/Quasar/Prelude.hs
+
30
−
13
View file @
8b47674f
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE PolyKinds #-}
module
Quasar.Prelude
(
module
Base
Prelude
,
(
module
Prelude
,
module
Quasar
.
PreludeExtras
,
(
>=>
),
(
<=<
),
Control
.
Applicative
.
liftA2
,
module
Control
.
Concurrent
.
MVar
,
Control
.
Exception
.
Exception
,
Control
.
Exception
.
SomeException
,
Control
.
Exception
.
throwIO
,
Control
.
Monad
.
forever
,
Control
.
Monad
.
unless
,
...
...
@@ -16,15 +15,25 @@ module Quasar.Prelude
Control
.
Monad
.
forM
,
Control
.
Monad
.
forM_
,
Control
.
Monad
.
join
,
Data
.
Unique
.
Unique
,
Data
.
Unique
.
newUnique
,
Data
.
Void
.
Void
,
Hashable
.
Hashable
,
GHC
.
Generics
.
Generic
,
MonadIO
,
liftIO
,
Maybe
.
catMaybes
,
Maybe
.
fromMaybe
,
Maybe
.
listToMaybe
,
Maybe
.
maybeToList
,
Data
.
Maybe
.
catMaybes
,
Data
.
Maybe
.
fromMaybe
,
Data
.
Maybe
.
listToMaybe
,
Data
.
Maybe
.
maybeToList
,
Data
.
Int
.
Int8
,
Data
.
Int
.
Int16
,
Data
.
Int
.
Int32
,
Data
.
Int
.
Int64
,
Data
.
Word
.
Word8
,
Data
.
Word
.
Word16
,
Data
.
Word
.
Word32
,
Data
.
Word
.
Word64
,
error
,
errorWithoutStackTrace
,
head
,
...
...
@@ -43,26 +52,34 @@ module Quasar.Prelude
)
where
import
"base"
Prelude
as
Base
Prelude
hiding
import
Prelude
hiding
(
error
,
errorWithoutStackTrace
,
head
,
last
,
read
,
-- Due to the accepted "monad of no return" proposal, return becomes an
-- alias for pure. Return can be a pitfall for newcomers, so we decided to
-- use pure instead.
return
,
undefined
,
)
import
qualified
"base"
Prelude
as
P
import
qualified
Prelude
as
P
import
Quasar.PreludeExtras
import
qualified
Control.Applicative
import
Control.Concurrent.MVar
import
qualified
Control.Exception
import
qualified
Control.Monad
import
qualified
Data.Void
import
Control.Monad
((
>=>
),
(
<=<
))
import
Control.Monad.IO.Class
(
MonadIO
,
liftIO
)
import
qualified
Data.Hashable
as
Hashable
import
qualified
Data.Maybe
as
Maybe
import
qualified
Data.Int
import
qualified
Data.Maybe
import
qualified
Data.Unique
import
qualified
Data.Void
import
qualified
Data.Word
import
qualified
Debug.Trace
as
Trace
import
qualified
GHC.Generics
import
qualified
GHC.Stack.Types
...
...
This diff is collapsed.
Click to expand it.
src/Quasar/PreludeExtras.hs
+
22
−
4
View file @
8b47674f
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE PackageImports #-}
module
Quasar.PreludeExtras
where
-- Use prelude from `base` to prevent module import cycle.
import
"base"
Prelude
import
Prelude
import
Quasar.Utils.ExtraT
import
Control.Applicative
(
liftA2
)
import
Control.Concurrent
(
threadDelay
)
import
Control.Monad.State.Lazy
as
State
import
qualified
Data.Char
as
Char
import
qualified
Data.Hashable
as
Hashable
...
...
@@ -16,7 +14,10 @@ import qualified Data.HashMap.Strict as HM
import
qualified
Data.HashSet
as
HS
import
qualified
Data.List
as
List
import
qualified
Data.Maybe
as
Maybe
import
GHC.Records.Compat
(
HasField
,
getField
,
setField
)
import
qualified
GHC.Stack.Types
import
GHC.TypeLits
(
Symbol
)
import
Lens.Micro.Platform
(
Lens
'
,
lens
)
impossibleCodePath
::
GHC
.
Stack
.
Types
.
HasCallStack
=>
a
impossibleCodePath
=
error
"Code path marked as impossible was reached"
...
...
@@ -51,6 +52,7 @@ leftToMaybe :: Either a b -> Maybe a
leftToMaybe
(
Left
x
)
=
Just
x
leftToMaybe
(
Right
_
)
=
Nothing
-- | Returns all duplicate elements in a list. The order of the produced list is unspecified.
duplicates
::
forall
a
.
(
Eq
a
,
Hashable
.
Hashable
a
)
=>
[
a
]
->
[
a
]
duplicates
=
HS
.
toList
.
duplicates'
HS
.
empty
where
...
...
@@ -87,3 +89,19 @@ infixr 6 <<>>
dup
::
a
->
(
a
,
a
)
dup
x
=
(
x
,
x
)
-- | Enumerate all values of an 'Enum'
enumerate
::
(
Enum
a
,
Bounded
a
)
=>
[
a
]
enumerate
=
[
minBound
..
maxBound
]
-- | Splits a list using a predicate. The separator is removed. The opposite of `intercalate`.
splitOn
::
(
a
->
Bool
)
->
[
a
]
->
[[
a
]]
splitOn
p
s
=
case
break
p
s
of
(
w
,
[]
)
->
[
w
]
(
w
,
_
:
r
)
->
w
:
splitOn
p
r
fieldLens
::
forall
(
x
::
Symbol
)
r
a
.
HasField
x
r
a
=>
Lens'
r
a
fieldLens
=
lens
(
getField
@
x
)
(
setField
@
x
)
sleepForever
::
IO
a
sleepForever
=
forever
$
threadDelay
1000000000000
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment