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:  consing an element to a list inside a file ([email protected])
   2.  ffi woes (Jose A. Ortega Ruiz)
   3. Re:  [OT] Haskell-inspired functions for BASH (Marc Weber)
   4. Re:  Linux install walkthrough (Marc D. Migge)
   5. Re:  ffi woes (Stephen Tetley)
   6.  Decent Haskell REPL? (Jon Harrop)
   7. Re:  Decent Haskell REPL? (Tom Tobin)
   8.  Re: ffi woes (Jose A. Ortega Ruiz)
   9.  Translating imperative algorithms to Haskell (Mikhail Novikov)


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

Message: 1
Date: Fri, 19 Feb 2010 01:54:05 +0100
From: [email protected]
Subject: Re: [Haskell-beginners] consing an element to a list inside a
        file
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

ok, looks much easier and works :)

But what are now the correct signatures for the function? Normally the "one and 
only" function should be: readCal :: IO Calendar
My function are: readCal = readCal2 datelist
and: readCal2 datelist = do... which returns the Calendar (the list of dates)


-------- Original-Nachricht --------
> Datum: Fri, 19 Feb 2010 00:41:56 +0100
> Von: Daniel Fischer <[email protected]>
> An: [email protected]
> CC: [email protected]
> Betreff: Re: [Haskell-beginners] consing an element to a list inside a file

> Am Freitag 19 Februar 2010 00:25:18 schrieb [email protected]:
> > ok, now I did it by just calling from the original function by to a new
> > one with an empty list at the beginning.
> >
> > How can I add the date at the end of the list? By creating a new list
> > from the new date and using concat or is there a simpler way?
> >
> 
> Better stick it to the front by (:) and reverse the list just before 
> printing.

-- 
NEU: Mit GMX DSL über 1000,- ¿ sparen!
http://portal.gmx.net/de/go/dsl02


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

Message: 2
Date: Fri, 19 Feb 2010 02:13:11 +0100
From: "Jose A. Ortega Ruiz" <[email protected]>
Subject: [Haskell-beginners] ffi woes
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii


Hi,

Show below is a short program using the FFI to access libiw and provide,
given an interface name such as "wlan0" the associated ESSID. One uses
iw_get_basic_config to fill a struct wireless_config (dynamically
allocated), and extract from that the desired string, which is a field
of type char[MAX_ESSID_LEN] in said struct type.

When i run this program (or call getWirelessInfo inside ghci) with an
existing network interface, it segfaults (calling it with a non-existent
one returns the expected empty string, so the problem is after the first
'if' in getWirelessInfo): can anybody spot what am i doing wrong? Or
perhaps give me any hint on how to debug the issue?

TIA!
jao

{-# LANGUAGE CPP, ForeignFunctionInterface #-}

module Main (main) where

import System.Environment
import Foreign
import Foreign.C.Types
import Foreign.C.String

#include <iwlib.h>

foreign import ccall "iwlib.h iw_sockets_open"
  c_iw_open :: IO CInt

foreign import ccall "unistd.h close"
  c_iw_close :: CInt -> IO ()

-- the 3rd argument is a struct wireless_config*, an input parameter
foreign import ccall "iwlib.h iw_get_basic_config"
  c_iw_basic_config :: CInt -> CString -> Ptr () -> IO CInt

-- Given a network interface name, return its ESSID
getWirelessInfo :: String -> IO String
getWirelessInfo iface =
  allocaBytes (#size struct wireless_config) $ \wc ->
  withCString iface $ \istr -> do
    i <- c_iw_open
    r <- c_iw_basic_config i istr wc
    c_iw_close i
    if (r < 0)
      then return ""
      else do hase <- (#peek struct wireless_config, has_essid) wc :: IO CInt
              eon <- (#peek struct wireless_config, essid_on) wc :: IO CInt
              if hase > 0 && eon > 0
                then do l <- (#peek struct wireless_config, essid_len) wc
                        e <- (#peek struct wireless_config, essid) wc
                        -- wireless_config.essid is a char[MAX_LEN]
                        peekCStringLen (e, fromIntegral (l :: CInt))
                else return ""

main = (fmap head getArgs) >>= getWirelessInfo >>= print



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

Message: 3
Date: Fri, 19 Feb 2010 04:31:47 +0100
From: Marc Weber <[email protected]>
Subject: Re: [Haskell-beginners] [OT] Haskell-inspired functions for
        BASH
To: beginners <[email protected]>
Message-ID: <1266548909-sup-4...@nixos>
Content-Type: text/plain; charset=UTF-8

Your project is nice.

I never thougt about how much effort it is to write

cmd | while read f; do basename $f; done

cmd | map basename

*is* much easier.

For now I just put
map(){ while read l; do $@ "$l"; done; }

into my .bashrc. Having a simple parser which parses the "lambda"
funtion to split cols could be interesting. Example

ecoh -e "a b\nb c" | map "\1 2 ->  echo $2"
should output the second col or such. (separating values by spaces or
tabs. There are at least two tools which can do this as well:

| awk '{ print $2}': or such or man col. Probably there are more tools.

The Windows-Powershell even let's you pass objects. However it's command
line interface is horrible compared to bash / zsh. But I think they're
working on this. Also you could use some Vim tools to workaround this.

There was another attempt to create many tools using Haskell. I don't
recall the name. Just open hackage and search for "Shell".

On the other hand let me tell you what my experience is. I do shell
scripting once in a while. However bash/sh sucks if you have to do more
complicated things.
It can be done but you start fighting with the language or learning
details about it you don't want to know.
Eg the difference 

echo "foo" | while ... done
in contrast to
while ... done <<< "foo"

The first one opens a subshell which means if you assign local vars you
can't use the results outside of the loop.

So additionally to your attempt I highly recommend you learning a
scripting language such as Ruby or Python to get some things done.
Why do I *not* recommend haskell here? Because compiling scripts will
use much disk space (Haskell applications tend to be big) and ghci
startup time is bad compared to either Python or Ruby. So you can image
than you have to wait 5secs using a pipe like this:
echa | app1 | app2 | app3 | app4
just because ghci has to startup and load some libraries.


Anyway there are many projects which could server your needs. Eg
http://www.focusresearch.com/gregor/sw/psh/ yet another.

Before spending much effort on your library I'd spend some time
searching the net to see what is available.. Also make sure to search
the haskell-cafe mailinglist. I think you'll find some pointers there as
well. Whil searching the web don't miss autopager (FireFox plugin).

Good luck and thank you for your map shortcut idea!

Marc Weber


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

Message: 4
Date: Wed, 17 Feb 2010 22:07:12 +0100
From: "Marc D. Migge" <[email protected]>
Subject: Re: [Haskell-beginners] Linux install walkthrough
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi,

maybe you can be a little more specific, as to what problems you ran 
into? I just installed Leksah on Ubuntu via "cabal install" and (using 
the proper constraints) it worked like a charm. Install info for Leksah 
is here:

http://www.haskell.org/haskellwiki/Leksah_Installation


I didn't bother to install the haskell-platform though. Up to now I 
could get all the packages I needed from the Ubuntu repos or Hackage 
without problems.

Best regards,
Marc


Adrian Adshead wrote:
> Hi Lakshmi,
> I've had two attempts at getting it going, the first I didn't get very far 
> beforedeciding to give other, more up to date, linuxes a go, but had little 
> luck onthat front. Next time around I got further but ran out of time. The 
> problem isthat I want to spend my time writing software (and I have a windows 
> systemup and running) not trying to fight to get the system working. I really 
> didn'tthink it would be too much to ask that a simple install script would 
> exist,or at least a HowTo for one of the more popular linuxes (RedHat).
> I will have another look at it this weekend and see how far I get. If I 
> manageto succeed I will document the process and post it to the wiki. Haskell 
> seemsto be a great language and there are lots of helpful people in the 
> communitywho are willing to help newbies like myself get off the ground, but 
> when the'system' fights back as much as it does I'm not surprised that not 
> many peopleuse haskell, it's just easier to use something else.
> --- On Wed, 17/2/10, Lakshmi Narasimhan <[email protected]> wrote:
> 
> From: Lakshmi Narasimhan <[email protected]>
> Subject: Re: [Haskell-beginners] Linux install walkthrough
> To: [email protected]
> Cc: [email protected]
> Date: Wednesday, 17 February, 2010, 13:30
> 
> Hi Adrian,
> 
> Were you able to get the installation of Leksah done ? I haven't tried 
> installing leksah from cabal in centos myself but it would be good to know 
> whether it is possible to get leksah built without having to upgrade gtk and 
> glib in Centos 5.4. In that case, we might be able to use some rpms from 
> fedora haskell platform.
> 
> 
> On Wed, Feb 17, 2010 at 6:34 PM, Stephen Tetley <[email protected]> 
> wrote:
> 
> Hi Adrian
> 
> 
> 
> Is Centos close enough to RedHat to use Fedora packages?
> 
> 
> 
> The Haskell-Platform seemingly is available as a package:
> 
> 
> 
> https://admin.fedoraproject.org/pkgdb/users/packages/haskell-sig
> 
> 
> 
> Leksah has a fairly large set of dependencies so installing it might
> 
> take some work - particularly where it depends on packages outside the
> 
> Haskell Plaform (GTK, etc...) you might well want versions from
> 
> Hackage rather than ones prepackaged for Fedora. It might be worth
> 
> asking on the Fedora-Haskell-devel mailing list for better advice.
> 
> 
> 
> Best wishes
> 
> 
> 
> Stephen
> 
> _______________________________________________
> 
> Beginners mailing list
> 
> [email protected]
> 
> http://www.haskell.org/mailman/listinfo/beginners
> 
> 
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners



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

Message: 5
Date: Fri, 19 Feb 2010 11:39:39 +0000
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] ffi woes
To: "Jose A. Ortega Ruiz" <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hello Jose


Looking at the source for iwlib.h the wireless_config struct doesn't
have an essid_len field, at least in this version which seems to be
current one:

* Version :    22      16.3.07

That said, if you are using this version then hsc2hs (the FFI
preprocessor) should be throwing an error along the lines of

error: structure has no member named 'essid_len'

What command line flags are you using to compile?

Best wishes

Stephen


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

Message: 6
Date: Fri, 19 Feb 2010 19:57:50 +0000
From: Jon Harrop <[email protected]>
Subject: [Haskell-beginners] Decent Haskell REPL?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="us-ascii"


GHCI seems to require type definitions to be described in a separate file and 
then loaded into the REPL, which is seriously tedious.

Are there any Haskell REPLs that don't have such limitations and, preferably, 
use JIT compilation instead of an interpreter?

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e


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

Message: 7
Date: Fri, 19 Feb 2010 12:46:30 -0600
From: Tom Tobin <[email protected]>
Subject: Re: [Haskell-beginners] Decent Haskell REPL?
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Fri, Feb 19, 2010 at 1:57 PM, Jon Harrop <[email protected]> wrote:
>
> GHCI seems to require type definitions to be described in a separate file and
> then loaded into the REPL, which is seriously tedious.
>
> Are there any Haskell REPLs that don't have such limitations and, preferably,
> use JIT compilation instead of an interpreter?

I run Haskell in an inferior shell in Emacs alongside haskell-mode;
it's easy to get immediate feedback to my changes that way.


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

Message: 8
Date: Fri, 19 Feb 2010 19:28:34 +0100
From: "Jose A. Ortega Ruiz" <[email protected]>
Subject: [Haskell-beginners] Re: ffi woes
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii


Hi Stephen,

Stephen Tetley <[email protected]> writes:

> Hello Jose
>
>
> Looking at the source for iwlib.h the wireless_config struct doesn't
> have an essid_len field, at least in this version which seems to be
> current one:
>
> * Version :    22      16.3.07
>
> That said, if you are using this version then hsc2hs (the FFI
> preprocessor) should be throwing an error along the lines of
>
> error: structure has no member named 'essid_len'

I'm using the iwlib.h that comes with debian's libiw-dev package, which
claims to be version 30 9.4 of wireless tools (it's not clear to me to
what version of libiw that corresponds). At any rate, the iwlib.h in my
system defines a wireless_config struct with an essid_len (and hsc2hs is
thus not complaining). If i try to read the string from essid using
peekCString i also get a segfault.

> What command line flags are you using to compile?

i do a plain 'hsc2hs Wireless.hsc' and then either 'ghci -liw
Wireless.hs' (to try interactively) or 'ghc -o wire -liw Wireless.hs'.
I've also tried adding -O, but the results are the same.

Thanks a lot for your help,
jao



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

Message: 9
Date: Fri, 19 Feb 2010 22:07:19 +0200
From: Mikhail Novikov <[email protected]>
Subject: [Haskell-beginners] Translating imperative algorithms to
        Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

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

Hello!

Four days ago I decided to try to learn Haskell by participating in Google AI 
Challenge (http://csclub.uwaterloo.ca/contest/). I went with LYAH and 
Real-World Haskell and I had no problems with functional core of Haskell, as I 
have lispy background. The problems begun when I tried to move my code to use 
different kind of decision algorithms, like negascout or flood fill.

I have found a ready made solution for negascout 
(http://hackage.haskell.org/packages/archive/game-tree/0.1.0.0/doc/html/src/Data-Tree-Game_tree-Negascout.html),
 but I was quite shocked by it's complexity, especially considering the 
relative easy of imperative algorithm.(http://en.wikipedia.org/wiki/Negascout). 
IMHO it is just TOO extremely complex and hard to read :/

In flood fill situation is similar - I need to track all the colored squares 
among 4 lines of recursion and I couldn't find a reasonable way to do it 
without going to infinite recursion or having lots of duplicates.

So basically, I wonder if there is some generic way to transfer imperative 
algorithms with local state to functional style without making them overly 
complex.

Thanks a lot, Mikhail
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkt+73cACgkQPHyh4sfuKrl7NgCeKHrIdJbHrSse6z7eRrmAi6ck
yYoAoIRJZLq6RVUcCG2Zf5Xc5tRW5YBk
=oUX7
-----END PGP SIGNATURE-----


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

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


End of Beginners Digest, Vol 20, Issue 29
*****************************************

Reply via email to