[Haskell-cafe] (SPAM 3)Re: handling NULL value in database query with Maybe (or other ...)

Damien Mattei mattei at oca.eu
Wed Dec 19 09:34:08 UTC 2018


i had many answers, i can not answer to all,first thanks
just afew words, i did not want to have a C beahvior at all,i try to
escape from the C world...
(the solution with Just and Nothing help a lot)
i espected something like that too, the answer have been given to me in
comp.lang.haskell:

 bd_rows_WDS  :: [Maybe Text] <- query conn qry_head_WDS (Only
(name::String))

but it fails to compile:

*Main> :load UpdateSidonie
[1 of 1] Compiling Main             ( UpdateSidonie.hs, interpreted )

UpdateSidonie.hs:213:5: error:
    Illegal type signature: ‘[Maybe Text]’
      Type signatures are only allowed in patterns with ScopedTypeVariables
    |
213 |     bd_rows_WDS  :: [Maybe Text] <- query conn qry_head_WDS (Only
(name::String))
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.

and i completely agree that Haskell is more safe than C/C++
even if as quoted here: https://esham.io/
it requires ,to do basic things " a Ph.D. and three Monoid instances "...

quoted from "But zsh in particular lets you write text manipulation
one-liners which in Haskell would require a Ph.D. and three Monoid
instances. "
:-)

Le 18/12/2018 20:06, Michael Walker a écrit :
> On Tue, 18 Dec 2018 at 15:34, 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)
>>    printf("NULL\n");
>> else
>>    printf("%s",*x);
>>
>> i expected more from Haskell...
> 
> Well, you have to remember to do that in C, but in Haskell the
> compiler won't let you use a "Maybe a" as an "a".  They're totally
> different things.
> 
> That seems a pretty huge benefit to me, even ignoring everything else.
> What more could you want?
> 

-- 
Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS


More information about the Haskell-Cafe mailing list