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:  Translating imperative algorithms to Haskell (Tom Tobin)
   2. Re:  Translating imperative algorithms to Haskell (Stephen Tetley)
   3.  Re: ffi woes (Jose A. Ortega Ruiz)
   4. Re:  Linux install walkthrough (Adrian Adshead)
   5.  Re: ffi woes (Dean Herington)
   6.  Re: ffi woes (Jose A. Ortega Ruiz)
   7.  list of integers to list of nats ([email protected])
   8. Re:  Decent Haskell REPL? (Jon Harrop)


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

Message: 1
Date: Fri, 19 Feb 2010 16:17:37 -0600
From: Tom Tobin <[email protected]>
Subject: Re: [Haskell-beginners] Translating imperative algorithms to
        Haskell
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Fri, Feb 19, 2010 at 4:10 PM, Mikhail Novikov <[email protected]> wrote:
> Maybe I should look into ST monad for this. :) I am still interested if there 
> is a way to make this kind of functions in purely functional way.

I *think* the answer to your question is "no".  You can write
imperative code in Haskell (via ST and IO), and you can write
functional code that gets equivalent results to a given chunk of
imperative code, but you can't directly translate imperative code to
functional code, since they're two qualitatively different things.
It's like asking to express a square in terms of a circle -- you can
come up with a circle that has the same area, but it's definitely
*not* a square.  :-)


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

Message: 2
Date: Fri, 19 Feb 2010 23:06:57 +0000
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Translating imperative algorithms to
        Haskell
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hello all

Particularly concerning the negascout algorithm, there doesn't seem to
be much in the algorithm presented on Wikipedia that couldn't be done
purely functionally with a fairly equivalent line count (might need a
auxiliary tree type and a tree fold). The 'imperativeness' in this
case only seems to be assignment to accumulators.

The version on Hackage doesn't seem to define an actual tree data type
only a tree-like type class, which while making things general does
appear to make things complicated.

Best wishes

Stephen


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

Message: 3
Date: Fri, 19 Feb 2010 23:15:18 +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

Stephen Tetley <[email protected]> writes:

> Hi
>
> I think I've found a version 30 from Debian's archive - the essid
> string is fixed length, rather than sized by essid_len (even though
> essid_len is now in the struct). Is this the same as the version you
> have?

Yes, it is. I've tried to read the essid field both using peekCString,
as in

   s <- (#peek struct wireless_info, essid)
   peekCString s

and providing explicitly the maximum length of essid (34) to
peekCStringLen. Do you mean that for a struct field that is a of type
char[LEN] those peek functions are innappropriate?

(I've checked using C that essid_len actually gets the correct value,
and that the contents of essid is null-terminated, i.e.
wi.essid[wi.essid_len] == '\0' is always true).

Thanks,
jao

>
>
> /* Structure for storing all wireless information for each device
>  * This is a cut down version of the one above, containing only
>  * the things *truly* needed to configure a card.
>  * Don't add other junk, I'll remove it... */
> typedef struct wireless_config
> {
>   char                name[IFNAMSIZ + 1];     /* Wireless/protocol name */
>   int         has_nwid;
>   iwparam     nwid;                   /* Network ID */
>   int         has_freq;
>   double      freq;                   /* Frequency/channel */
>   int         freq_flags;
>   int         has_key;
>   unsigned char       key[IW_ENCODING_TOKEN_MAX];     /* Encoding key used */
>   int         key_size;               /* Number of bytes */
>   int         key_flags;              /* Various flags */
>   int         has_essid;
>   int         essid_on;
>   char                essid[IW_ESSID_MAX_SIZE + 2];   /* ESSID (extended 
> network) */
>   int         essid_len;
>   int         has_mode;
>   int         mode;                   /* Operation mode */
> } wireless_config;
>
> Best wishes
>
> Stephen



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

Message: 4
Date: Sat, 20 Feb 2010 02:22:26 +0000 (GMT)
From: Adrian Adshead <[email protected]>
Subject: Re: [Haskell-beginners] Linux install walkthrough
To: Lakshmi Narasimhan <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

I had another go at getting it going.
leksah 0.6.1 requires gtk2hs >= 0.10gtk2hs 0.10.1 requires gtksourceview >= 
2.2gtksourceview 2.2 requires gtk+ >= 2.12gtk+ >=2.12 requires upgraded glib
So the answer is no, it is not installable on Centos withoutupgrade to gtk and 
glib.
The fedora 12 install works and I have leksah and my wx appworking, but 
unfortunately I use NX to open a remote sessionto the server and leksah does 
something to crash the connection,so I can not use it anyway.
Adrian.

--- 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




-- 
Regards
Lakshmi Narasimhan T V




      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100219/1ec6b4b4/attachment-0001.html

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

Message: 5
Date: Sat, 20 Feb 2010 03:04:42 -0500
From: Dean Herington <[email protected]>
Subject: [Haskell-beginners] Re: ffi woes
To: "Jose A. Ortega Ruiz" <[email protected]>, [email protected]
Message-ID: <a06240801c7a5467ca...@[192.168.1.100]>
Content-Type: text/plain; charset="us-ascii" ; format="flowed"

At 11:15 PM +0100 2/19/10, Jose A. Ortega Ruiz wrote:
>Stephen Tetley <[email protected]> writes:
>
>>  Hi
>>
>>  I think I've found a version 30 from Debian's archive - the essid
>>  string is fixed length, rather than sized by essid_len (even though
>>  essid_len is now in the struct). Is this the same as the version you
>>  have?
>
>Yes, it is. I've tried to read the essid field both using peekCString,
>as in
>
>    s <- (#peek struct wireless_info, essid)
>    peekCString s
>
>and providing explicitly the maximum length of essid (34) to
>peekCStringLen. Do you mean that for a struct field that is a of type
>char[LEN] those peek functions are innappropriate?
>
>(I've checked using C that essid_len actually gets the correct value,
>and that the contents of essid is null-terminated, i.e.
>wi.essid[wi.essid_len] == '\0' is always true).
>
>Thanks,
>jao
>
>>
>>
>>  /* Structure for storing all wireless information for each device
>>   * This is a cut down version of the one above, containing only
>>   * the things *truly* needed to configure a card.
>>   * Don't add other junk, I'll remove it... */
>>  typedef struct wireless_config
>>  {
>>    char              name[IFNAMSIZ + 1];     /* Wireless/protocol name */
>>    int               has_nwid;
>>    iwparam   nwid;                   /* Network ID */
>>    int               has_freq;
>>    double    freq;                   /* Frequency/channel */
>>    int               freq_flags;
>>    int               has_key;
>>    unsigned char     key[IW_ENCODING_TOKEN_MAX];     /* Encoding key used */
>>    int               key_size;               /* Number of bytes */
>>    int               key_flags;              /* Various flags */
>>    int               has_essid;
>>    int               essid_on;
>>    char              essid[IW_ESSID_MAX_SIZE + 2];   /* ESSID 
>>(extended network) */
>>    int               essid_len;
>>    int               has_mode;
>>    int               mode;                   /* Operation mode */
>>  } wireless_config;
>>
>>  Best wishes
>>
>  > Stephen

Though I'm not an FFI expert, I'll take a stab in case it might help you.

It seems to me that

>    s <- (#peek struct wireless_info, essid)
>    peekCString s

would read a pointer from the essid field, which is clearly not what 
you want.  I think you'd want to use #ptr.  Maybe something like the 
following (untested!):

     l <- (#peek struct wireless_config, essid_len) wc
     p <- (#ptr struct wireless_info, essid) wc
     -- wireless_config.essid is a char[MAX_LEN]
     peekCStringLen (p, fromIntegral (l :: CInt))

Dean


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

Message: 6
Date: Sat, 20 Feb 2010 10:10:26 +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 Dean,

Dean Herington <[email protected]> writes:


[...]

> Though I'm not an FFI expert, I'll take a stab in case it might help you.
>
> It seems to me that
>
>>    s <- (#peek struct wireless_info, essid)
>>    peekCString s
>
> would read a pointer from the essid field, which is clearly not what
> you want.  I think you'd want to use #ptr.  Maybe something like the
> following (untested!):
>
>     l <- (#peek struct wireless_config, essid_len) wc
>     p <- (#ptr struct wireless_info, essid) wc
>     -- wireless_config.essid is a char[MAX_LEN]
>     peekCStringLen (p, fromIntegral (l :: CInt))
>

Right, using #ptr works (with the minor modification that it doesn't
return its value inside IO, so one must use let p =..., instead of p <-
...).

Thanks a lot for your help.

Cheers,
jao



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

Message: 7
Date: Sat, 20 Feb 2010 12:39:30 +0100
From: [email protected]
Subject: [Haskell-beginners] list of integers to list of nats
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Hi,
I have to write a function which maps a list of integers to a list of the 
corresponding nats. The following code is already there:

data Nat = Z | S Nat deriving (Eq,Ord,Show)

instance Enum Nat where
    toEnum i | i < 0        = error "Enum_Nat.toEnum: Negative integer"
             | i == 0       = Z
             | otherwise    = S (toEnum (i-1))

the function should be: mapIntsToNats :: [Int] -> Maybe [Nat]
so for example: [2,0,1,3] should make: [S (S Z), Z, S Z, S (S (S Z))]

how can I do that?



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


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

Message: 8
Date: Sat, 20 Feb 2010 15:31:31 +0000
From: Jon Harrop <[email protected]>
Subject: Re: [Haskell-beginners] Decent Haskell REPL?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="utf-8"

On Friday 19 February 2010 18:46:30 Tom Tobin wrote:
> 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.

What's your procedure for getting ghci to interpret a type definition?

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


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

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


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

Reply via email to