Database.HaskellDB.Get

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
-- | Utility for getting values from the DB with HaskellDB.

module Database.HaskellDB.Get
  (getValueWith
  ,GetValue(..)
  ,GetInstances(..)) where

import Database.HaskellDB.Database (GetValue(..),GetInstances(..))

-- | Get a value from the database with the given parser and label.
getValueWith
  :: (Show b,GetValue b)
  => (b -> Maybe a) -- ^ Parser.
  -> String -- ^ Label.
  -> (GetInstances s -> s -> String -> IO a) -- ^ GetValue method.
getValueWith get name =
  \fs s f -> do
    value <- getValue fs s f
    case get value of
      Just ok -> return ok
      Nothing -> fail $ "GetValue.getValueWith." ++ name ++
                        ": Unable to parse: " ++ f ++ " -> " ++ show value
14:6: Warning: Redundant bracket
Found:
String -> (GetInstances s -> s -> String -> IO a)
Why not:
String -> GetInstances s -> s -> String -> IO a
16:1: Error: Redundant lambda
Found:
getValueWith get name
= \ fs s f ->
do value <- getValue fs s f
case get value of
Just ok -> return ok
Nothing -> fail $
"GetValue.getValueWith." ++
name ++ ": Unable to parse: " ++ f ++ " -> " ++ show value
Why not:
getValueWith get name fs s f
= do value <- getValue fs s f
case get value of
Just ok -> return ok
Nothing -> fail $
"GetValue.getValueWith." ++
name ++ ": Unable to parse: " ++ f ++ " -> " ++ show value