Skip to content

Commit

Permalink
Reformatted.
Browse files Browse the repository at this point in the history
Added workflows.
  • Loading branch information
brianjosephmckeon committed Feb 2, 2024
1 parent 6cbfc92 commit 2d484d0
Show file tree
Hide file tree
Showing 25 changed files with 634 additions and 591 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@byteverse/l3c
12 changes: 12 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: build
on:
pull_request:
branches:
- "*"

jobs:
call-workflow:
uses: byteverse/.github/.github/workflows/build.yaml@main
secrets: inherit
with:
release: false
12 changes: 12 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: release
on:
push:
tags:
- "*"

jobs:
call-workflow:
uses: byteverse/.github/.github/workflows/build.yaml@main
secrets: inherit
with:
release: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode/
dist
dist-*
cabal-dev
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog for unpacked-maybe-numeric

## 0.1.1.0 -- 2019-09-28

* Add module for `Word128`-variant of `Maybe`.
5 changes: 0 additions & 5 deletions ChangeLog.md

This file was deleted.

2 changes: 0 additions & 2 deletions Setup.hs

This file was deleted.

51 changes: 51 additions & 0 deletions fourmolu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Number of spaces per indentation step
indentation: 2

# Max line length for automatic line breaking
column-limit: 200

# Styling of arrows in type signatures (choices: trailing, leading, or leading-args)
function-arrows: trailing

# How to place commas in multi-line lists, records, etc. (choices: leading or trailing)
comma-style: leading

# Styling of import/export lists (choices: leading, trailing, or diff-friendly)
import-export-style: leading

# Whether to full-indent or half-indent 'where' bindings past the preceding body
indent-wheres: false

# Whether to leave a space before an opening record brace
record-brace-space: true

# Number of spaces between top-level declarations
newlines-between-decls: 1

# How to print Haddock comments (choices: single-line, multi-line, or multi-line-compact)
haddock-style: multi-line

# How to print module docstring
haddock-style-module: null

# Styling of let blocks (choices: auto, inline, newline, or mixed)
let-style: auto

# How to align the 'in' keyword with respect to the 'let' keyword (choices: left-align, right-align, or no-space)
in-style: right-align

# Whether to put parentheses around a single constraint (choices: auto, always, or never)
single-constraint-parens: always

# Output Unicode syntax (choices: detect, always, or never)
unicode: never

# Give the programmer more choice on where to insert blank lines
respectful: true

# Fixity information for operators
fixities: []

# Module reexports Fourmolu should know about
reexports: []

78 changes: 37 additions & 41 deletions src/Data/Maybe/Unpacked/Numeric/Complex/Double.hs
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedSums #-}
{-# LANGUAGE UnboxedTuples #-}

module Data.Maybe.Unpacked.Numeric.Complex.Double
( Complex(..)
( Complex (..)
, toBaseComplex
, fromBaseComplex

, Maybe(..)
, Maybe (..)
, just
, nothing

, maybe

, isJust
, isNothing
, fromMaybe
, listToMaybe
, maybeToList
, catMaybes
, mapMaybe

, toBaseMaybe
, fromBaseMaybe
) where
import Prelude hiding (Maybe,maybe)
) where

import Prelude hiding (Maybe, maybe)

import qualified Data.Complex as C
import GHC.Base (build)
import GHC.Exts (Double#,Double(D#),(==##))
import GHC.Exts (Double (D#), Double#, (==##))

import GHC.Read (Read(readPrec), expectP)
import Text.Read (parens, Lexeme(Ident), lexP, (+++))
import GHC.Read (Read (readPrec), expectP)
import Text.ParserCombinators.ReadPrec (prec, step)
import Text.Read (Lexeme (Ident), lexP, parens, (+++))
import qualified Prelude as P

data Complex = Complex Double# Double#
Expand All @@ -44,20 +37,20 @@ toBaseComplex :: Complex -> C.Complex Double
toBaseComplex (Complex d1# d2#) = (D# d1#) C.:+ (D# d2#)

fromBaseComplex :: C.Complex Double -> Complex
fromBaseComplex ( (D# d1#) C.:+ (D# d2#) ) = Complex d1# d2#
fromBaseComplex ((D# d1#) C.:+ (D# d2#)) = Complex d1# d2#

instance Eq Complex where
Complex a b == Complex c d =
case a ==## c of
1# -> case b ==## d of
1# -> True
_ -> False
_ -> False
_ -> False
_ -> False

instance Show Complex where
showsPrec p (Complex a b)
= showParen (p >= 11)
$ showString "Complex "
showsPrec p (Complex a b) =
showParen (p >= 11) $
showString "Complex "
. showsPrec 11 (D# a)
. showString " "
. showsPrec 11 (D# b)
Expand All @@ -73,30 +66,33 @@ data Maybe = Maybe (# (# #) | Complex #)

instance Eq Maybe where
ma == mb =
maybe (isNothing mb)
(\a -> maybe False (\b -> a == b) mb) ma

maybe
(isNothing mb)
(\a -> maybe False (\b -> a == b) mb)
ma

instance Show Maybe where
showsPrec p (Maybe m) = case m of
(# (# #) | #) -> showString "nothing"
(# | c #) -> showParen (p > 10)
$ showString "just "
. showsPrec 11 c
(# | c #) ->
showParen (p > 10) $
showString "just "
. showsPrec 11 c

instance Read Maybe where
readPrec = parens $ nothingP +++ justP
where
nothingP = do
Ident "nothing" <- lexP
return nothing
justP = prec 10 $ do
Ident "just" <- lexP
a <- step readPrec
return (just a)
where
nothingP = do
Ident "nothing" <- lexP
return nothing
justP = prec 10 $ do
Ident "just" <- lexP
a <- step readPrec
return (just a)

listToMaybe :: [Complex] -> Maybe
listToMaybe [] = nothing
listToMaybe (x:_) = just x
listToMaybe (x : _) = just x

maybeToList :: Maybe -> [Complex]
maybeToList = maybe [] (: [])
Expand All @@ -108,13 +104,14 @@ mapMaybe :: (a -> Maybe) -> [a] -> [Complex]
mapMaybe _ [] = []
mapMaybe f (a : as) =
let ws = mapMaybe f as
in maybe ws (: ws) (f a)
in maybe ws (: ws) (f a)
{-# NOINLINE [1] mapMaybe #-}

{-# RULES
"mapMaybe" [~1] forall f xs. mapMaybe f xs
= build (\c n -> foldr (mapMaybeFB c f) n xs)
"mapMaybeList" [1] forall f. foldr (mapMaybeFB (:) f) [] = mapMaybe f
"mapMaybe" [~1] forall f xs.
mapMaybe f xs =
build (\c n -> foldr (mapMaybeFB c f) n xs)
"mapMaybeList" [1] forall f. foldr (mapMaybeFB (:) f) [] = mapMaybe f
#-}

{-# NOINLINE [0] mapMaybeFB #-}
Expand Down Expand Up @@ -148,4 +145,3 @@ toBaseMaybe = maybe P.Nothing P.Just

fromBaseMaybe :: P.Maybe Complex -> Maybe
fromBaseMaybe = P.maybe nothing just

76 changes: 36 additions & 40 deletions src/Data/Maybe/Unpacked/Numeric/Complex/Float.hs
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedSums #-}
{-# LANGUAGE UnboxedTuples #-}

module Data.Maybe.Unpacked.Numeric.Complex.Float
( Complex(..)
( Complex (..)
, toBaseComplex
, fromBaseComplex

, Maybe(..)
, Maybe (..)
, just
, nothing

, maybe

, isJust
, isNothing
, fromMaybe
, listToMaybe
, maybeToList
, catMaybes
, mapMaybe

, toBaseMaybe
, fromBaseMaybe
) where
) where

import Prelude hiding (Maybe,maybe)
import Prelude hiding (Maybe, maybe)

import qualified Data.Complex as C
import GHC.Base (build)
import GHC.Exts (Float#,Float(F#),eqFloat#)
import GHC.Exts (Float (F#), Float#, eqFloat#)

import GHC.Read (Read(readPrec), expectP)
import Text.Read (parens, Lexeme(Ident), lexP, (+++))
import GHC.Read (Read (readPrec), expectP)
import Text.ParserCombinators.ReadPrec (prec, step)
import Text.Read (Lexeme (Ident), lexP, parens, (+++))
import qualified Prelude as P

data Complex = Complex Float# Float#
Expand All @@ -44,20 +37,20 @@ toBaseComplex :: Complex -> C.Complex Float
toBaseComplex (Complex d1# d2#) = (F# d1#) C.:+ (F# d2#)

fromBaseComplex :: C.Complex Float -> Complex
fromBaseComplex ( (F# d1#) C.:+ (F# d2#) ) = Complex d1# d2#
fromBaseComplex ((F# d1#) C.:+ (F# d2#)) = Complex d1# d2#

instance Eq Complex where
Complex a b == Complex c d =
case a `eqFloat#` c of
1# -> case b `eqFloat#` d of
1# -> True
_ -> False
_ -> False
_ -> False
_ -> False

instance Show Complex where
showsPrec p (Complex a b)
= showParen (p >= 11)
$ showString "Complex "
showsPrec p (Complex a b) =
showParen (p >= 11) $
showString "Complex "
. showsPrec 11 (F# a)
. showString " "
. showsPrec 11 (F# b)
Expand All @@ -73,30 +66,33 @@ data Maybe = Maybe (# (# #) | Complex #)

instance Eq Maybe where
ma == mb =
maybe (isNothing mb)
(\a -> maybe False (\b -> a == b) mb) ma

maybe
(isNothing mb)
(\a -> maybe False (\b -> a == b) mb)
ma

instance Show Maybe where
showsPrec p (Maybe m) = case m of
(# (# #) | #) -> showString "nothing"
(# | c #) -> showParen (p > 10)
$ showString "just "
. showsPrec 11 c
(# | c #) ->
showParen (p > 10) $
showString "just "
. showsPrec 11 c

instance Read Maybe where
readPrec = parens $ nothingP +++ justP
where
nothingP = do
Ident "nothing" <- lexP
return nothing
justP = prec 10 $ do
Ident "just" <- lexP
a <- step readPrec
return (just a)
where
nothingP = do
Ident "nothing" <- lexP
return nothing
justP = prec 10 $ do
Ident "just" <- lexP
a <- step readPrec
return (just a)

listToMaybe :: [Complex] -> Maybe
listToMaybe [] = nothing
listToMaybe (x:_) = just x
listToMaybe (x : _) = just x

maybeToList :: Maybe -> [Complex]
maybeToList = maybe [] (: [])
Expand All @@ -108,13 +104,14 @@ mapMaybe :: (a -> Maybe) -> [a] -> [Complex]
mapMaybe _ [] = []
mapMaybe f (a : as) =
let ws = mapMaybe f as
in maybe ws (: ws) (f a)
in maybe ws (: ws) (f a)
{-# NOINLINE [1] mapMaybe #-}

{-# RULES
"mapMaybe" [~1] forall f xs. mapMaybe f xs
= build (\c n -> foldr (mapMaybeFB c f) n xs)
"mapMaybeList" [1] forall f. foldr (mapMaybeFB (:) f) [] = mapMaybe f
"mapMaybe" [~1] forall f xs.
mapMaybe f xs =
build (\c n -> foldr (mapMaybeFB c f) n xs)
"mapMaybeList" [1] forall f. foldr (mapMaybeFB (:) f) [] = mapMaybe f
#-}

{-# NOINLINE [0] mapMaybeFB #-}
Expand Down Expand Up @@ -148,4 +145,3 @@ toBaseMaybe = maybe P.Nothing P.Just

fromBaseMaybe :: P.Maybe Complex -> Maybe
fromBaseMaybe = P.maybe nothing just

Loading

0 comments on commit 2d484d0

Please sign in to comment.