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.  Error message: "Couldn't match expected type" (S. H. Aegis)
   2. Re:  Error message: "Couldn't match expected      type"
      (Brandon Allbery)
   3. Re:  Error message: "Couldn't match expected      type" (S. H. Aegis)


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

Message: 1
Date: Fri, 3 Oct 2014 01:40:30 +0900
From: "S. H. Aegis" <[email protected]>
To: "[email protected]" <[email protected]>
Subject: [Haskell-beginners] Error message: "Couldn't match expected
        type"
Message-ID:
        <cajp-nqy8srtndymuemh4dhg2w83fukxtp1ywdup3nida2uw...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hello.

I'm learning Haskell on OSX.
How can I fix this error message?
(Code from The Haskell School of Expression, P40)
Sorry for border you...

Sok.

import Graphics.SOE

main() =
    runGraphics (
    do  w <- openWindow "My First Graphics Program" (300, 300)
        drawInWindow w (text(100, 200) "HelloFraphicsWorld")
        spaceClose w
    )

spaceClose :: Window -> IO()
spaceClose w
    =   do  k <- getKey w
            if k == ' ' then closeWindow w
                        else spaceClose w


[1 of 1] Compiling Main             ( firstGraphics.hs, firstGraphics.o )

firstGraphics.hs:3:1:
    Couldn't match expected type `IO t0' with actual type `() -> IO ()'
    In the expression: main
    When checking the type of the function `main'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20141003/bbfd9ce6/attachment-0001.html>

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

Message: 2
Date: Thu, 2 Oct 2014 12:49:56 -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] Error message: "Couldn't match
        expected        type"
Message-ID:
        <cakfcl4ujlrqfaazlrz582jmj+1gcovyr47pvieoxwhzngcj...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Thu, Oct 2, 2014 at 12:40 PM, S. H. Aegis <[email protected]> wrote:

> main() =


You have declared (well, described, but by type inference that's the same
thing) main to take a parameter of type "unit" (empty tuple). main doesn't
take parameters.

Haskell parameters do not work the way most common languages do; using
parentheses in function calls the way you would in C/Java/Python etc. will
generally get you unexpected type errors, because you're telling it you're
passing tuples around. So, the function call

    f()    (f :: () -> a)

is different from

    f    (f :: a)

and the function call

    f(a, b)    (f :: (a,b) -> c)

is different from

    f a b    (f :: a -> b -> c)

(The inferred type of `f` is shown after each call.)

-- 
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/20141002/721797ef/attachment-0001.html>

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

Message: 3
Date: Fri, 3 Oct 2014 01:55:40 +0900
From: "S. H. Aegis" <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Error message: "Couldn't match
        expected        type"
Message-ID:
        <cajp-nqzt9ef5rqtjhdjcoueuvjkxlqub8qegz-_o9jyixjj...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Oh... my...
Thank you so much.
Maybe, I'm confused with C.
Fix main() to main, it works! =)
Thank you again, and have a nice day.

Sincerely, Sok

2014-10-03 1:49 GMT+09:00 Brandon Allbery <[email protected]>:

> On Thu, Oct 2, 2014 at 12:40 PM, S. H. Aegis <[email protected]> wrote:
>
>> main() =
>
>
> You have declared (well, described, but by type inference that's the same
> thing) main to take a parameter of type "unit" (empty tuple). main doesn't
> take parameters.
>
> Haskell parameters do not work the way most common languages do; using
> parentheses in function calls the way you would in C/Java/Python etc. will
> generally get you unexpected type errors, because you're telling it you're
> passing tuples around. So, the function call
>
>     f()    (f :: () -> a)
>
> is different from
>
>     f    (f :: a)
>
> and the function call
>
>     f(a, b)    (f :: (a,b) -> c)
>
> is different from
>
>     f a b    (f :: a -> b -> c)
>
> (The inferred type of `f` is shown after each call.)
>
> --
> brandon s allbery kf8nh                               sine nomine
> associates
> [email protected]
> [email protected]
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>


-- 
Sok Ha, CHANG
Dr. Chang's Clinic. #203. 503-23. AmSa-Dong, GangDong-Gu, Seoul.
Tel: +82-2-442-7585
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20141003/ff3eadfa/attachment-0001.html>

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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 76, Issue 3
****************************************

Reply via email to