wxHaskell and do statements

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

wxHaskell and do statements

mempko
Hello, I have a program that just will not compile and I cannot figure
out why. I am starting out with wxHaskell but keep getting certain
errors. Here is the source:

-------------------------
module Main where

import Graphics.UI.WX

main :: IO ()
main = start hello

hello :: IO ()
hello = do f <- frame [text := "Super Window"]
                lab <- staticText f [text:= "Hello"]
                quit <- button f [text:= "Quit", on command := close f]
                touch <- button f [text:= "Touch Me",
                                on command := set quit [text:= "Yay"]]
               
                set f [layout:= floatCenter (widget lab) $
                                floatCenter (widget touch) $
                                floatCenter (widget quit)]



------------------
I keep the following error

****
Compiling Main             ( test1.hs, test1.o )

test1.hs:9:11: The last statement in a 'do' construct must be an expression
*****

I looked at source code for the do statement and can not understand why
I get that error.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: wxHaskell and do statements

Malcolm Wallace
mempko <[hidden email]> writes:

> Hello, I have a program that just will not compile and I cannot figure
> out why.

Wrong indentation.  Tab stops are 8 spaces in Haskell, but your code
seems to assume 6 spaces.

> -------------------------
> module Main where
>
> import Graphics.UI.WX
>
> main :: IO ()
> main = start hello
>
> hello :: IO ()
> hello = do f <- frame [text := "Super Window"]
> lab <- staticText f [text:= "Hello"]

The 'lab <-' actually lines up with 'frame', not with 'f <-' as intended.

Regards,
    Malcolm
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: wxHaskell and do statements

Sara Kenedy
In reply to this post by mempko
Sorry for interuption. In some days later, I have to work with
Graphs.UI, too. So I tried to run your example below, but I met a
compiled error

Prelude> :load graph.hs
Reading file "graph.hs":
Reading file "Graphics.UI.WX":
ERROR "Graphics.UI.WX" - Unable to open file "Graphics.UI.WX"

I guess the error happened because my hugs (and ghci) do not have WX,
or I do not give some options to the command for compiling. Is it
right ? Thank you for your consideration.

On 11/28/05, mempko <[hidden email]> wrote:

> Hello, I have a program that just will not compile and I cannot figure
> out why. I am starting out with wxHaskell but keep getting certain
> errors. Here is the source:
>
> -------------------------
> module Main where
>
> import Graphics.UI.WX
>
> main :: IO ()
> main = start hello
>
> hello :: IO ()
> hello = do f <- frame [text := "Super Window"]
>                 lab <- staticText f [text:= "Hello"]
>                 quit <- button f [text:= "Quit", on command := close f]
>                 touch <- button f [text:= "Touch Me",
>                                 on command := set quit [text:= "Yay"]]
>
>                 set f [layout:= floatCenter (widget lab) $
>                                 floatCenter (widget touch) $
>                                 floatCenter (widget quit)]
>
>
>
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: wxHaskell and do statements

mempko
In reply to this post by Malcolm Wallace
Malcolm Wallace wrote:

> mempko <[hidden email]> writes:
>
>> Hello, I have a program that just will not compile and I cannot figure
>> out why.
>
> Wrong indentation.  Tab stops are 8 spaces in Haskell, but your code
> seems to assume 6 spaces.
>
>> -------------------------
>> module Main where
>>
>> import Graphics.UI.WX
>>
>> main :: IO ()
>> main = start hello
>>
>> hello :: IO ()
>> hello = do f <- frame [text := "Super Window"]
>> lab <- staticText f [text:= "Hello"]
>
> The 'lab <-' actually lines up with 'frame', not with 'f <-' as intended.
>
> Regards,
>     Malcolm


I found that using ';' at the end of expressions helped and also adding
a "return()" statement. You were also right that it did not line up,
thank you. Now does haskell understand tabs, or does my editor have to
convert the tabs to spaces?


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Re: wxHaskell and do statements

Sebastian Sylvan
On 11/29/05, mempko <[hidden email]> wrote:

> Malcolm Wallace wrote:
> > mempko <[hidden email]> writes:
> >
> >> Hello, I have a program that just will not compile and I cannot figure
> >> out why.
> >
> > Wrong indentation.  Tab stops are 8 spaces in Haskell, but your code
> > seems to assume 6 spaces.
> >
> >> -------------------------
> >> module Main where
> >>
> >> import Graphics.UI.WX
> >>
> >> main :: IO ()
> >> main = start hello
> >>
> >> hello :: IO ()
> >> hello = do f <- frame [text := "Super Window"]
> >>              lab <- staticText f [text:= "Hello"]
> >
> > The 'lab <-' actually lines up with 'frame', not with 'f <-' as intended.
> >
> > Regards,
> >     Malcolm
>
>
> I found that using ';' at the end of expressions helped and also adding
> a "return()" statement. You were also right that it did not line up,
> thank you. Now does haskell understand tabs, or does my editor have to
> convert the tabs to spaces?

IIRC Haskell assumes a tab is 8 spaces.
IMO that's way too much. Haskell tends to take up quite a bit of
horizontal real-estate so I usually go with 2 spaces.

At any rate, I set my editor to convert them to spaces.

/S
--
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Re: wxHaskell and do statements

Sven Panne
Am Dienstag, 29. November 2005 16:16 schrieb Sebastian Sylvan:
> IIRC Haskell assumes a tab is 8 spaces.

Correctly, it is explicitly specified in the Haskell spec, see:

   http://haskell.org/onlinereport/syntax-iso.html#layout

> IMO that's way too much. Haskell tends to take up quite a bit of
> horizontal real-estate so I usually go with 2 spaces.
>
> At any rate, I set my editor to convert them to spaces.

I think this in general the best idea for all projects, even if the language
in question has no layout rule. Tabs are simply evil...

Cheers,
   S.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe