[Haskell-beginners] Lazyness and forM_

Marc Busqué marc at lamarciana.com
Fri Apr 13 13:32:27 UTC 2018

On Fri, 13 Apr 2018, Kim-Ee Yeoh wrote:

> Well, 
> forM_ (categories, expenses) $ withDB . createTable
> is equivalent to 
> withDB . createTable $ expenses.
> So exactly one table is created.

Oops, you are right.

>       ```
>       ["a", "b"] `forM_` print
>       ```
>       Actually prints both `"a"` and `"b"`.
> Here the code uses square brackets--and so we have honest-to-goodness lists--whereas the previous used parentheses.
> See what happens with: ("a","b") `forM_` print.

Now I feel embarrassed I overlooked that :)

I used a tuple instead of a list because in selda `Table` are type-safe.
So `categories` and `expenses` are different types and they can't go in
the same list.

So I guess, once the `forM_` mistery is gone, I can boil down my problem
to something very different. As it has nothing to do with the current
subject, I'll submit another question.

> Marc: Feel free to write to the haskell-cafe mailing list for questions such as this. Fortuitously in this case, it turns out that your query
> needed knowledge only about the forM* combinators and--ever since their ilk was generalized--the known instances declared for the Traversable
> constraint. As you explore the domain-specific package "selda" further, you will find more people acquainted with the package over at the cafe
> than here in beginners. Suffice to say, everyone here in this list is also in cafe, which is also open to beginners questions.

And following your recommendation I'll submit that question in the
haskell-cafe mailing list :)

Thank you very much for your help :)

Marc Busqué

More information about the Beginners mailing list