Skip to content

Commit

Permalink
Merge branch 'develop-remove-ifelse' into develop. Close nasa#150.
Browse files Browse the repository at this point in the history
**Description**

The dependency on `IfElse` is quite unnecessary: it seems like the only
function we use from that library is `awhen :: Monad m => Maybe a -> (a
-> m ()) -> m ()`, which is a type-specialized version of
[`Data.Foldable.for_`.](https://hackage.haskell.org/package/base-4.20.0.1/docs/Data-Foldable.html#v:for_).
Since the latter is in `base`, we can simplify Ogma by removing the
dependency on `IfElse`.

**Type**

- Management: Reduce technical debt, in compliance with style guide.

**Additional context**

None.

**Requester**

- Ivan Perez

**Method to check presence of bug**

The following dockerfile checks that no cabal package depends on IfElse,
in which case it prints the message "Success":

```Dockerfile
FROM ubuntu:focal

RUN apt-get update

RUN apt-get install --yes git

SHELL ["/bin/bash", "-c"]
CMD git clone $REPO \
    && cd $NAME \
    && git checkout $COMMIT \
    && ! grep -niHre 'IfElse' --include='*.cabal' ogma** \
    && echo "Success"
```

Command (substitute variables based on new path after merge):

```sh
$ docker run -e "REPO=https://github.com/NASA/ogma" -e "NAME=ogma" -e PAT="ogma-" -e "COMMIT=<HASH>" -it ogma-verify-150
```

**Expected result**

Running the dockerfile above prints the message "Success", indicating
that IfElse is not required by any library in ogma.

**Solution implemented**

Replace calls to `awhen`, from IfElse, with calls to `for_`, from
Data.Foldable.

Remove the dependency on IfElse from all cabal files.

**Further notes**

None.
  • Loading branch information
ivanperez-keera committed Sep 22, 2024
2 parents 62a45e8 + 0db6542 commit c4d7386
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
4 changes: 4 additions & 0 deletions ogma-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for ogma-core

## [1.4.X] - 2024-09-21

* Remove dependency on IfElse (#150).

## [1.4.0] - 2024-05-21

* Version bump 1.4.0 (#145).
Expand Down
1 change: 0 additions & 1 deletion ogma-core/ogma-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ library
, aeson >= 2.0.0.0 && < 2.2
, bytestring
, filepath
, IfElse
, mtl

, ogma-extra >= 1.4.0 && < 1.5
Expand Down
4 changes: 2 additions & 2 deletions ogma-core/src/Command/FRETComponentSpec2Copilot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ module Command.FRETComponentSpec2Copilot
where

-- External imports
import Control.Monad.IfElse ( awhen )
import Data.Aeson ( eitherDecode, decode )
import Data.ByteString.Lazy (fromStrict)
import Data.Foldable (for_)

-- External imports: auxiliary
import Data.ByteString.Extra as B ( safeReadFile )
Expand Down Expand Up @@ -91,7 +91,7 @@ fretComponentSpec2Copilot fp options = do
let (mOutput, result) =
fretComponentSpec2CopilotResult options fp copilot

awhen mOutput putStrLn
for_ mOutput putStrLn
return result

-- | Print the contents of a Copilot module that implements the Past-time TL
Expand Down
8 changes: 4 additions & 4 deletions ogma-core/src/Command/FRETReqsDB2Copilot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ module Command.FRETReqsDB2Copilot
where

-- External imports
import Control.Monad.IfElse ( awhen )
import Data.Aeson ( eitherDecode )
import Data.List ( nub, (\\) )
import Data.Aeson (eitherDecode)
import Data.Foldable (for_)
import Data.List (nub, (\\))

-- External imports: auxiliary
import Data.ByteString.Extra as B ( safeReadFile )
Expand Down Expand Up @@ -88,7 +88,7 @@ fretReqsDB2Copilot fp options = do
let (mOutput, result) =
fretReqsDB2CopilotResult options fp copilot

awhen mOutput putStrLn
for_ mOutput putStrLn
return result

-- | Print the contents of a Copilot module that implements the Past-time TL
Expand Down

0 comments on commit c4d7386

Please sign in to comment.