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

Paul aquagnu at gmail.com
Wed Dec 19 12:24:02 UTC 2018


So, add this extension. I think it would be:


{-# LANGUAGE ScopedTypeVariables #-}

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



@Ian: Example with unsafeCoerce is not correct: how is "unsafeCoerce" 
related to Maybe/pattern matching? True is that Haskell is not safe, for 
example, it has unsafe functions fromJust, etc, while pattern-matching 
is only the right way to "extract" value from Maybe (OK, also "maybe" 
function). Ian, by the way, how can you guarantee that Segmentation 
Fault will not happen in Haskell application? I hit even freezing of 
Haskell apps, Haskell is not a language with such assertions. May be it 
will be Rust, but Haskell - never.

19.12.2018 11:34, Damien Mattei wrote:
> 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?
>>



More information about the Haskell-Cafe mailing list