Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Manage the type of a variable in the show    implementation
      (Kim-Ee Yeoh)
   2. Re:  Manage the type of a variable in the show    implementation
      (Christian Sperandio)
   3. Re:  Type error in sub-function (???)
   4. Re:  Type error in sub-function (Brandon Allbery)


----------------------------------------------------------------------

Message: 1
Date: Wed, 23 Jul 2014 19:42:01 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Manage the type of a variable in the
        show    implementation
Message-ID:
        <capy+zdtcmui2jbv-pqqd6re1r9otk8sc6jqk_khdm1u3ml1...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Wed, Jul 23, 2014 at 7:40 PM, Chadda? Fouch? <[email protected]>
wrote:

> Anyway, using Show for this is wrong, Show is supposed to translate
> datatypes in a form you could copy in your code to get the value back, it
> isn't supposed to be for presentation. You have libraries that do pretty
> formatting better.


Very insightful, thanks!

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140723/df6977c3/attachment-0001.html>

------------------------------

Message: 2
Date: Wed, 23 Jul 2014 15:04:29 +0200
From: Christian Sperandio <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Manage the type of a variable in the
        show    implementation
Message-ID:
        <cakc7jjjmurf2ptmo05g8zh2h1wnd9cpjx-knnq0u8c3oqvq...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I chose the newtype solution.

Thanks :)



2014-07-23 14:40 GMT+02:00 Chadda? Fouch? <[email protected]>:

> On Wed, Jul 23, 2014 at 2:20 PM, Christian Sperandio <
> [email protected]> wrote:
>
>> I know the quote problem comes from the show function on String value.
>> How could I do a show for no-string values and return directly the value
>> for strings?
>>
>
> You can't ! (ok you can but you'll need to use OverlappingInstances)
>
> Anyway, using Show for this is wrong, Show is supposed to translate
> datatypes in a form you could copy in your code to get the value back, it
> isn't supposed to be for presentation. You have libraries that do pretty
> formatting better.
>
> If you absolutely want this, I would suggest writing another class for it
> and use OverlappingInstances to allow for one "DataLog String" instance and
> one "(Show a) => YourClass (DataLog a)" instance.
>
> Another possibility is to do a newtype for strings that have a Show
> instance that doesn't put quotes around. That might even be a better idea,
> maybe your Strings really represent variables or something in this case
> anyway ?
> --
> Jeda?
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140723/ee19c14d/attachment-0001.html>

------------------------------

Message: 3
Date: Wed, 23 Jul 2014 23:18:11 +0900
From: ??? <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Type error in sub-function
Message-ID:
        <calmycjp6ozdgufy_w96_mj8gh3hmzyupw2g-mb+fg1_brc3...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thank you all for kind replies.

But I'm not sure whether I grasp the gist.
Actual code is as follows.
I want to scan the query argument of HTTP get method and
build response object according to the query arguments.
I use fold and the scanQuery function should return IO object
for some reason.

Since parseHeader function is fold function and uses query and request
variable at the same time, I cannot write as a separate function.

scanQuery :: Request -> IO Object
scanQuery request = do
        let (p, query) = parseUrl (path request)
        foldM parseHeader defObject query
            where parseHeader obj (name, Just value) =
                      case name of
                        "len" -> return obj { contentLength = read value }
                        "type" -> return obj { contentType =
parseContentType value }
                        "rate" -> return obj { rate = Just value }
                        "status" -> return obj { httpStatus = read value }
                        ('x':'x':name2) -> return obj { clientReqHdr =
((name2, vv) : prev) }
                           where prev = clientReqHdr obj
                                 vv = case value of
                                        "client_ip_addr" -> clientIp request
                                        "now" -> do utcTime <-
currentUTCTime
                                                    return $ formatRFC1123
utcTime
                                        _ -> value
                        _ -> return obj

However, above code does not compile also :-(
*Main> :l test
[1 of 1] Compiling Main             ( test.hs, interpreted )

test.hs:101:64:
    Couldn't match expected type `[t0]' with actual type `IO UTCTime'
    In a stmt of a 'do' block: utcTime <- currentUTCTime
    In the expression:
      do { utcTime <- currentUTCTime;
           return $ formatRFC1123 utcTime }
    In a case alternative:
        "now"
          -> do { utcTime <- currentUTCTime;
                  return $ formatRFC1123 utcTime }
Failed, modules loaded: none.

Obviously outer do-block is inside IO monad, as the type of scanQuery is
Request -> IO Object. But GHC puts inner do-block (in "now" case)  inside
list monad,
doesn't it? Why does ghc look for List monad?

Lost in monad,

Chul-Woong





2014-07-23 21:33 GMT+09:00 Kim-Ee Yeoh <[email protected]>:

>
> On Wed, Jul 23, 2014 at 7:08 PM, ??? <[email protected]> wrote:
>
>> Since the return type of foo Func is IO String and
>> first case statement has "return timedVal",
>> I think that ghc expects the type of timedVal as String.
>> However, the error message shows that
>> ghc expects timedVal should have type IO b0.
>>
>
> It's not really about timedVal nor the case 'statement'. (The scare quotes
> are because there are only expressions, not statements, in haskell.)
>
> Consider the difference between
>
> do { putStrLn "hello"; True; }
>
> and
>
> do { putStrLn "hello"; return True; }
>
> Which one throws an error and why?
>
>
> -- Kim-Ee
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140723/2d02001b/attachment-0001.html>

------------------------------

Message: 4
Date: Wed, 23 Jul 2014 10:22:57 -0400
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Type error in sub-function
Message-ID:
        <CAKFCL4W3XeMai=q-gdcrg3pzkoolxdqafpdz9sjldgjvpuk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Wed, Jul 23, 2014 at 10:18 AM, ??? <[email protected]> wrote:

>                         ('x':'x':name2) -> return obj { clientReqHdr =
> ((name2, vv) : prev) }
>                            where prev = clientReqHdr obj
>                                  vv = case value of
>                                         "client_ip_addr" -> clientIp
> request
>                                         "now" -> do utcTime <-
> currentUTCTime
>                                                     return $ formatRFC1123
> utcTime
>                                         _ -> value
>                         _ -> return obj
>
> However, above code does not compile also :-(
> *Main> :l test
> [1 of 1] Compiling Main             ( test.hs, interpreted )
>
> test.hs:101:64:
>     Couldn't match expected type `[t0]' with actual type `IO UTCTime'
>     In a stmt of a 'do' block: utcTime <- currentUTCTime
>     In the expression:
>       do { utcTime <- currentUTCTime;
>            return $ formatRFC1123 utcTime }
>     In a case alternative:
>         "now"
>           -> do { utcTime <- currentUTCTime;
>                   return $ formatRFC1123 utcTime }
> Failed, modules loaded: none.
>
> Obviously outer do-block is inside IO monad, as the type of scanQuery is
> Request -> IO Object. But GHC puts inner do-block (in "now" case)  inside
> list monad,
> doesn't it? Why does ghc look for List monad?
>

Because you're treating vv as a pure value when you use it, so ghc looks
for a way to treat it as a monad and concludes that it is a List. If you
want it to be in IO, you need to use <- on its result, not use it directly.

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140723/e4238630/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 73, Issue 17
*****************************************

Reply via email to