Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redundant <$> should not trigger for lengthy LambdaCase #1589

Open
complyue opened this issue May 6, 2024 · 0 comments
Open

Redundant <$> should not trigger for lengthy LambdaCase #1589

complyue opened this issue May 6, 2024 · 0 comments

Comments

@complyue
Copy link

complyue commented May 6, 2024

Redundant <$> should not trigger for lengthy LambdaCase

  Map.lookup dbaPath <$> readIORef storeRef >>= \case
    Nothing -> do
      (hdr, da) <- mmapDBA @a (rootDir </> dbaPath) Nothing False
      modifyIORef' storeRef $ Map.insert dbaPath (DbaData hdr da)
      return (hdr, da)
    Just (DbaData hdr da@(DeviceArray _cap _fp :: DeviceArray a')) -> case eqT of
      Nothing ->
        throwIO . userError $
          "element type mismatch for dba in store: " ++ dbaPath
      Just (Refl :: a :~: a') -> return (hdr, da)

Point-free style is less optimal for lengthy LambdaCase blocks

Redundant <$>
Found:
  Map.lookup dbaPath <$> readIORef storeRef
  >>=
    \case
      Nothing
        -> do (hdr, da) <- mmapDBA @a (rootDir </> dbaPath) Nothing False
              modifyIORef' storeRef $ Map.insert dbaPath (DbaData hdr da)
              return (hdr, da)
      Just (DbaData hdr da@(DeviceArray _cap _fp :: DeviceArray a'))
        -> case eqT of
             Nothing
               -> throwIO . userError
                    $ "element type mismatch for dba in store: " ++ dbaPath
             Just (Refl :: a :~: a') -> return (hdr, da)
Why not:
  readIORef storeRef
  >>=
    (\case
       Nothing
         -> do (hdr, da) <- mmapDBA @a (rootDir </> dbaPath) Nothing False
               modifyIORef' storeRef $ Map.insert dbaPath (DbaData hdr da)
               return (hdr, da)
       Just (DbaData hdr da@(DeviceArray _cap _fp :: DeviceArray a'))
         -> case eqT of
              Nothing
                -> throwIO . userError
                     $ "element type mismatch for dba in store: " ++ dbaPath
              Just (Refl :: a :~: a') -> return (hdr, da))
      . Map.lookup dbaPath
hlint(refact:Redundant <$>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant