[Haskell-cafe] (SPAM 3)Re: handling NULL value in database query with Maybe (or other ...)
allbery.b at gmail.com
Tue Dec 18 15:58:00 UTC 2018
You seem rather confused about the topic. What magic were you expecting to
happen if something doesn't have a value?
The point of Maybe is it lets you (a) specify exactly where things can lack
a value (as, for example, when a database column can produce a NULL instead
of a value), and (b) explicitly handle those instead of hoping the program
somehow reads your mind to figure out how to deal with it or feeds you some
unexpected 'nil' or whatever.
Consider in this case that the database does not care if a column doesn't
happen to have any NULLs, it cares only that the column was not declared
NOT NULL and therefore *can* contain a NULL. Which is the same condition
where you use a Maybe someType in Haskell instead of simply someType.
In particular, if you were expecting a database NULL to turn into the empty
string or "NULL" or some other such in-band value, how were you expecting
to distinguish the case where the database row actually contains that
string? That's why databases have NULL to begin with: "no value" distinct
from any possible actual value. If you do not want this, declare the column
NOT NULL in the database, don't expect the client program to do magic for
On Tue, Dec 18, 2018 at 10:34 AM Damien Mattei <mattei at oca.eu> wrote:
> ok well i do not want to open a discussion here, but i do not see any
> benefit in Haskell using Nothing and Just compared to other language,
> it's the same than if i had written in C something like :
> if (x == NULL)
> i expected more from Haskell...
> ok reading twice the article in link, i admit there should be some
> adavantage using Nothing instead of null, such as type, and genericity
> and not being spcecific to alloated memory as in C ...
> Le 18/12/2018 16:16, Tom Ellis a écrit :
> > That is using Maybe and is not a null pointer!
> > Just and Nothing are the constructors of Maybe.
> > On Tue, Dec 18, 2018 at 03:43:35PM +0100, Damien Mattei wrote:
> >> thank you Tom, it is the kind of answer that help me
> >> i insert this and it is ok now:
> >> forM_ bd_rows_WDS $ \(Only x) ->
> >> case x of
> >> Nothing -> putStrLn ("x =" ++ "NULL")
> >> Just x -> putStrLn $ ("x =" ++ Text.unpack x)
> >> i had seen a such solution on web but thought the Maybe was the
> >> solution, i hoped asked could avoid using sort of Null pointer as
> >> mentioned in this article:
> >> if someone else have a simpler solution email me
> >> Le 18/12/2018 13:34, tom.stejskal a écrit :
> >>> case x of
> >>> Nothing -> putStrLn "NULL"
> >>> Just y -> putStrLn $ Text.unpack y
> > _______________________________________________
> > Haskell-Cafe mailing list
> > To (un)subscribe, modify options or view archives go to:
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> > Only members subscribed via the mailman list are allowed to post.
> Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
brandon s allbery kf8nh
allbery.b at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe