[Haskell-cafe] Selda, type operators and heterogeneous lists

Ben Franksen ben.franksen at online.de
Fri Apr 13 19:19:15 UTC 2018


Am 13.04.2018 um 16:38 schrieb Marc Busqué:
> On Fri, 13 Apr 2018, Tom Ellis wrote:
> 
>> On Fri, Apr 13, 2018 at 03:59:44PM +0200, Marc Busqué wrote:
>>
>> Before we can help we need to know more.  Specifically, why do you
>> want to
>> put them in a single list?
> 
> I want to make the same action with more than one (creating them in
> the database server):
> 
> ```
> migrate :: IO ()
> migrate = do
>     dir <- dBDir
>     createDirectoryIfMissing True dir
>     forM_ [categories, expenses]
>        $ withDB . createTable ```

So a possible solution is to store a list of actions instead of a list
of items (untested code):

    let dbCreateTable = withDB . createTable
    sequence_ $
        map dbCreateTable categories ++ map dbCreateTable expenses

or perhaps, if the types allow it:

    withDB $ do
        let dbCreateTable = withDB . createTable
        sequence_ $
            map createTable categories ++ map createTable expenses



More information about the Haskell-Cafe mailing list