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.  Editor to use for Hugs (patricklynch)
   2. Re:  Editor to use for Hugs (Brandon S Allbery KF8NH)
   3.  trouble installing glib on windows 7 (Michael Litchard)
   4.  Improve my FFI code please... (Sean Charles)
   5. Re:  trouble installing glib on windows 7 (aditya siram)
   6. Re:  Improve my FFI code please... (Edward Z. Yang)
   7. Re:  Improve my FFI code please... (Daniel Fischer)
   8. Re:  trouble installing glib on windows 7 (Michael Litchard)


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

Message: 1
Date: Thu, 20 Jan 2011 12:43:58 -0500
From: "patricklynch" <[email protected]>
Subject: [Haskell-beginners] Editor to use for Hugs
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

Good afternoon,

I am currently using VIM as an editor with Hugs on a Mac.

I tried TextEdit but I am looking for something more powerful.

Is there an editor that is designed to work with Hugs on the Mac?

Thank you

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110120/b2bfaca6/attachment-0001.htm>

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

Message: 2
Date: Thu, 20 Jan 2011 12:27:15 -0500
From: Brandon S Allbery KF8NH <[email protected]>
Subject: Re: [Haskell-beginners] Editor to use for Hugs
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 1/20/11 12:43 , patricklynch wrote:
> I am currently using VIM as an editor with Hugs on a Mac?
> I tried TextEdit but I am looking for something more powerful?
> Is there an editor that is designed to work with Hugs on the Mac?

Not so far as I know.  The Emacs Haskell mode should work reasonably well,
and there is a Haskell mode for TextWrangler/BBEdit.

http://www.cs.uu.nl/helium/docs/Editors.html might be helpful.
Sadly, the recent haskell.org move broke a lot of links including the one
for other editor modes on that page.

- -- 
brandon s. allbery     [linux,solaris,freebsd,perl]      [email protected]
system administrator  [openafs,heimdal,too many hats]  [email protected]
electrical and computer engineering, carnegie mellon university      KF8NH
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk04cHMACgkQIn7hlCsL25X8ZACgnW/1yc8UyBTn44p2n3bkfyWw
eMwAn3bOA0tQ8VXTiaEMNGSs8H5zJd0/
=LAsv
-----END PGP SIGNATURE-----



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

Message: 3
Date: Thu, 20 Jan 2011 15:27:17 -0800
From: Michael Litchard <[email protected]>
Subject: [Haskell-beginners] trouble installing glib on windows 7
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

I have Haskell Platform installed, trying to install glib. Here's what
happens.

$ cabal install glib
Resolving dependencies...
C:\Users\PERFOR~1\AppData\Local\Temp\glib-0.12.02360\glib-0.12.0\Gtk2HsSetup.hs:
25: warning: #warning Setup.hs is guessing the version of Cabal. If
compilation
of Setup.hs fails use -DCABAL_VERSION_MINOR=x for Cabal version 1.x.0 when
build
ing (prefixed by --ghc-option= when using the 'cabal' command)
[1 of 2] Compiling Gtk2HsSetup      (
C:\Users\PERFOR~1\AppData\Local\Temp\glib-
0.12.02360\glib-0.12.0\Gtk2HsSetup.hs,
C:\Users\PERFOR~1\AppData\Local\Temp\glib
-0.12.02360\glib-0.12.0\dist\setup\Gtk2HsSetup.o )
[2 of 2] Compiling Main             (
C:\Users\PERFOR~1\AppData\Local\Temp\glib-
0.12.02360\glib-0.12.0\Setup.hs,
C:\Users\PERFOR~1\AppData\Local\Temp\glib-0.12.
02360\glib-0.12.0\dist\setup\Main.o )
Linking
C:\Users\PERFOR~1\AppData\Local\Temp\glib-0.12.02360\glib-0.12.0\dist\se
tup\setup.exe ...
Configuring glib-0.12.0...
setup.exe: pkg-config version >=0.9.0 is required but it could not be found.
cabal.exe: Error: some packages failed to install:
glib-0.12.0 failed during the configure step. The exception was:
ExitFailure 1



Okay, so all I need to do is install pkg-config

$ cabal install pkg-config
cabal.exe: There is no package named pkg-config. Perhaps you need to run
'cabal update' first?

hmm, so how do I install pkg-config?
cabal update didn't help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110120/68ab2b0a/attachment-0001.htm>

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

Message: 4
Date: Thu, 20 Jan 2011 23:35:02 +0000
From: Sean Charles <[email protected]>
Subject: [Haskell-beginners] Improve my FFI code please...
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi list,

I am *still* cursing the fact that I like where Haskell is taking me but 
that I am too dumb to get it into my head as quickly as I'd like!
I will not give up and in that vein I have been beating myself up trying 
to run before I can walk as usual by attempting to write an FFI wrapper 
around the Ubuntu libcwiimote library!

Having been inspired by johnnylee.net and having found his code is for 
Windows and C# I have taken it on myself to reproduce what he's done but 
using Haskell and OpenGL. Laugh, I nearly cried because it's taken hours 
of frustration just to get this far! I've built the hardware and now I 
need the software as usual.

So, here we go... what I post here is the beginnings of a Wiimote 
wrapper. I *think* I understand Monads properly now, Brian Beck video on 
C9 (MSDN) really really helped a lot, I'd recommend that to anybody 
still struggling with the concept.

What I want to know is can my code be improved by using monadic chaining 
and if so, with what and how (LMAO) and also have I overlooked or 
otherwise not used the correct forms, idioms etc. to achieve what I have 
so far ? I am really keen to know how the real gurus out there could 
reduce this code down or make it 'more haskell like'.

Basically, I want you to correct it, improve it, show me and others how 
to do it right! I want it de-constructed, ripped to pieces, laughed at, 
openly mocked and I will learn from it and enjoy it because I am a 
developer! ;) LOL


It compiles with ...
     ghc --make -lcwiimote -o wmscan WiiMote.hs

and runs like so ...

    sean@sean-desktop:~/Documents/bluetooth$ ./wmscan 00:21:BD:A3:97:C7
    Connecting to 00:21:BD:A3:97:C7
    00:21:BD:A3:97:C7connected OK, disconnecting ...OK
    sean@sean-desktop:~/Documents/bluetooth$

...and I was proud as hell, almost as proud as watching my son born but 
without the goo.


Many thanks.
Sean

----

{-# LANGUAGE ForeignFunctionInterface #-}

import Foreign
import Foreign.C.Types
import Foreign.Ptr
import Foreign.C.String
import System


#include "wiimote_api.h"


foreign import ccall unsafe "wiimote_api.h wiimote_open"
   c_wiimote_open :: CString -> IO (Ptr Word8)

foreign import ccall unsafe "wiimote_api.h wiimote_close"
   c_wiimote_close :: (Ptr Word8) -> IO CInt


wiiOpen :: String -> IO (Maybe (Ptr Word8))
wiiOpen wid = do
   handle <- withCString wid c_wiimote_open
   case handle of
     nullPtr -> return Nothing
     handle -> return (Just handle)


wiiClose :: Ptr Word8 -> IO Bool
wiiClose wptr = do
     response <- c_wiimote_close wptr
     case response of
         0 -> return True
         _ -> return False


-- Open the wiiremote, print the handle and close it
test :: String -> IO ()
test wiiHID = do
     wiimote <- wiiOpen wiiHID
     case  wiimote of
         Just handle -> do
             putStr (wiiHID ++ " connected OK, disconnecting ... ")
             status <- wiiClose handle
             case status of
                 True -> putStrLn "OK"
                 False -> putStrLn "FAIL"
         Nothing -> putStrLn "FAIL"
     return ()


-- expects a single HID string on the command line ...
main :: IO ()
main = do
     args <- getArgs
     case args of
         [hid] -> do
             putStrLn ("Connecting to " ++ hid)
             test hid
         _ -> putStrLn "Supply ONE Wiimote HID address!"





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

Message: 5
Date: Thu, 20 Jan 2011 17:35:19 -0600
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] trouble installing glib on windows 7
To: Michael Litchard <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

I think you want the third-party pkg-config[1] tool. Are you trying to
install Gtk2hs by any chance?

-deech
[1] 
http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config_0.25-1_win32.zip

On Thu, Jan 20, 2011 at 5:27 PM, Michael Litchard <[email protected]> wrote:
> I have Haskell Platform installed, trying to install glib. Here's what
> happens.
>
> $ cabal install glib
> Resolving dependencies...
> C:\Users\PERFOR~1\AppData\Local\Temp\glib-0.12.02360\glib-0.12.0\Gtk2HsSetup.hs:
> 25: warning: #warning Setup.hs is guessing the version of Cabal. If
> compilation
> of Setup.hs fails use -DCABAL_VERSION_MINOR=x for Cabal version 1.x.0 when
> build
> ing (prefixed by --ghc-option= when using the 'cabal' command)
> [1 of 2] Compiling Gtk2HsSetup????? (
> C:\Users\PERFOR~1\AppData\Local\Temp\glib-
> 0.12.02360\glib-0.12.0\Gtk2HsSetup.hs,
> C:\Users\PERFOR~1\AppData\Local\Temp\glib
> -0.12.02360\glib-0.12.0\dist\setup\Gtk2HsSetup.o )
> [2 of 2] Compiling Main???????????? (
> C:\Users\PERFOR~1\AppData\Local\Temp\glib-
> 0.12.02360\glib-0.12.0\Setup.hs,
> C:\Users\PERFOR~1\AppData\Local\Temp\glib-0.12.
> 02360\glib-0.12.0\dist\setup\Main.o )
> Linking
> C:\Users\PERFOR~1\AppData\Local\Temp\glib-0.12.02360\glib-0.12.0\dist\se
> tup\setup.exe ...
> Configuring glib-0.12.0...
> setup.exe: pkg-config version >=0.9.0 is required but it could not be found.
> cabal.exe: Error: some packages failed to install:
> glib-0.12.0 failed during the configure step. The exception was:
> ExitFailure 1
>
>
>
> Okay, so all I need to do is install pkg-config
>
> $ cabal install pkg-config
> cabal.exe: There is no package named pkg-config. Perhaps you need to run
> 'cabal update' first?
>
> hmm, so how do I install pkg-config?
> cabal update didn't help
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>



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

Message: 6
Date: Thu, 20 Jan 2011 18:44:21 -0500
From: "Edward Z. Yang" <[email protected]>
Subject: Re: [Haskell-beginners] Improve my FFI code please...
To: Sean Charles <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <1295566815-sup-5564@ezyang>
Content-Type: text/plain; charset=UTF-8

The code looks basically fine.  Good job getting to this point.

* It is probably a good idea to give Ptr Word8 a newtype; something like
  Wiimote, to semantically represent what it is.

* Everyone loves bracketing functions! Write the function

    withWii :: String -> (Ptr Word8 -> IO ()) -> IO ()

  Don't call the inner lambda if getting the Wiimote fails.

* You can probably simplify 'test' a little bit by using exceptions
  and guards.  For example, instead of 'case status' you can write
  'when (not status) $ error "FAIL"'.  But this is a matter of taste
  and what you have isn't nested too deep.

Cheers,
Edward



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

Message: 7
Date: Fri, 21 Jan 2011 01:08:41 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Improve my FFI code please...
To: [email protected]
Cc: Sean Charles <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="iso-8859-1"

On Friday 21 January 2011 00:35:02, Sean Charles wrote:
> wiiOpen :: String -> IO (Maybe (Ptr Word8))
> wiiOpen wid = do
> ? ?handle <- withCString wid c_wiimote_open
> ? ?case handle of
> ? ? ?nullPtr -> return Nothing
> ? ? ?handle -> return (Just handle)

Unless nullPtr is a macro that gets replaced with a literal by the 
preprocessor, that won't do what you want. "nullPtr" is a generic name and 
matches everything, so you'll always take the first branch (with -Wall, ghc 
should warn about overlapping patterns in that case).



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

Message: 8
Date: Thu, 20 Jan 2011 16:17:20 -0800
From: Michael Litchard <[email protected]>
Subject: Re: [Haskell-beginners] trouble installing glib on windows 7
To: aditya siram <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

yeah, I think I need that. The point of this exercise is to install leksah.
But now I am re-evaluating if I need it or not.

On Thu, Jan 20, 2011 at 3:35 PM, aditya siram <[email protected]>wrote:

> I think you want the third-party pkg-config[1] tool. Are you trying to
> install Gtk2hs by any chance?
>
> -deech
> [1]
> http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config_0.25-1_win32.zip
>
> On Thu, Jan 20, 2011 at 5:27 PM, Michael Litchard <[email protected]>
> wrote:
> > I have Haskell Platform installed, trying to install glib. Here's what
> > happens.
> >
> > $ cabal install glib
> > Resolving dependencies...
> >
> C:\Users\PERFOR~1\AppData\Local\Temp\glib-0.12.02360\glib-0.12.0\Gtk2HsSetup.hs:
> > 25: warning: #warning Setup.hs is guessing the version of Cabal. If
> > compilation
> > of Setup.hs fails use -DCABAL_VERSION_MINOR=x for Cabal version 1.x.0
> when
> > build
> > ing (prefixed by --ghc-option= when using the 'cabal' command)
> > [1 of 2] Compiling Gtk2HsSetup      (
> > C:\Users\PERFOR~1\AppData\Local\Temp\glib-
> > 0.12.02360\glib-0.12.0\Gtk2HsSetup.hs,
> > C:\Users\PERFOR~1\AppData\Local\Temp\glib
> > -0.12.02360\glib-0.12.0\dist\setup\Gtk2HsSetup.o )
> > [2 of 2] Compiling Main             (
> > C:\Users\PERFOR~1\AppData\Local\Temp\glib-
> > 0.12.02360\glib-0.12.0\Setup.hs,
> > C:\Users\PERFOR~1\AppData\Local\Temp\glib-0.12.
> > 02360\glib-0.12.0\dist\setup\Main.o )
> > Linking
> > C:\Users\PERFOR~1\AppData\Local\Temp\glib-0.12.02360\glib-0.12.0\dist\se
> > tup\setup.exe ...
> > Configuring glib-0.12.0...
> > setup.exe: pkg-config version >=0.9.0 is required but it could not be
> found.
> > cabal.exe: Error: some packages failed to install:
> > glib-0.12.0 failed during the configure step. The exception was:
> > ExitFailure 1
> >
> >
> >
> > Okay, so all I need to do is install pkg-config
> >
> > $ cabal install pkg-config
> > cabal.exe: There is no package named pkg-config. Perhaps you need to run
> > 'cabal update' first?
> >
> > hmm, so how do I install pkg-config?
> > cabal update didn't help
> >
> >
> > _______________________________________________
> > 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/20110120/59194e19/attachment.htm>

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

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


End of Beginners Digest, Vol 31, Issue 19
*****************************************

Reply via email to