Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Ffi, memory allocation and failure (Edward Z. Yang)
   2. Re:  Ffi, memory allocation and failure (C Gosch)
   3. Re:  Ffi, memory allocation and failure (Antoine Latter)
   4.  question concerning conversion from one type to  another
      (Michael Litchard)
   5. Re:  question concerning conversion from one type to another
      (aditya siram)
   6. Re:  Ffi, memory allocation and failure (.)


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

Message: 1
Date: Wed, 09 Feb 2011 08:44:47 -0500
From: "Edward Z. Yang" <ezy...@mit.edu>
Subject: Re: [Haskell-beginners] Ffi, memory allocation and failure
To: "ch.go...@googlemail.com" <ch.go...@googlemail.com>
Cc: "beginners@haskell.org" <beginners@haskell.org>
Message-ID: <1297258860-sup-3239@ezyang>
Content-Type: text/plain; charset=UTF-8

Hello Christian,

Assuming that the foreign library is based off of mutation on matrices,
there's not an easy way to export a nice pure interface to them, because
they're not actually persistent: if another thread goes and modifies
some pointer which you also have in pure code, referential transparency
is broken.  So you'll have to think carefully about what sorts of guarantees
you can (or want) to make to Haskell, and if you can't fulfill them, keep
the code in IO (or create your own monad for manipulating matrices).

Edward



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

Message: 2
Date: Wed, 9 Feb 2011 15:57:32 +0100
From: C Gosch <ch.go...@googlemail.com>
Subject: Re: [Haskell-beginners] Ffi, memory allocation and failure
To: "Edward Z. Yang" <ezy...@mit.edu>
Cc: "beginners@haskell.org" <beginners@haskell.org>
Message-ID:
        <AANLkTi=zacvtm5zcarjmzrspw+t39dw8ctkctmrwn...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi Edward, hello to all list members,
thank you for your comments, I will keep that in mind. There will be
operations on matrices (and other objects) which modify the objects,
and those will be in IO or ST, I think.
However, I am planning to provide operations with matrices which guarantee
that each involved matrix is not changed, but which may return new matrices.
All matrices have to be allocated, and that allocation can fail ... how does
one usually go about this problem in Haskell?

Cheers,
Christian


2011/2/9 Edward Z. Yang <ezy...@mit.edu>

> Hello Christian,
>
> Assuming that the foreign library is based off of mutation on matrices,
> there's not an easy way to export a nice pure interface to them, because
> they're not actually persistent: if another thread goes and modifies
> some pointer which you also have in pure code, referential transparency
> is broken.  So you'll have to think carefully about what sorts of
> guarantees
> you can (or want) to make to Haskell, and if you can't fulfill them, keep
> the code in IO (or create your own monad for manipulating matrices).
>
> Edward
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110209/000cce8f/attachment-0001.htm>

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

Message: 3
Date: Wed, 9 Feb 2011 11:26:36 -0600
From: Antoine Latter <aslat...@gmail.com>
Subject: Re: [Haskell-beginners] Ffi, memory allocation and failure
To: C Gosch <ch.go...@googlemail.com>
Cc: "beginners@haskell.org" <beginners@haskell.org>
Message-ID:
        <AANLkTimmo+AuwPBzNX9rQ2=freygpj4bcgq+ct_7o...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Wed, Feb 9, 2011 at 8:57 AM, C Gosch <ch.go...@googlemail.com> wrote:
> Hi Edward, hello to all list members,
> thank you for your comments, I will keep that in mind. There will be
> operations on matrices (and other objects) which modify the objects,
> and those will be in IO or ST, I think.
> However, I am planning to provide operations with matrices which guarantee
> that each involved matrix is not changed, but which may return new matrices.
> All matrices have to be allocated, and that allocation can fail ... how does
> one usually go about this problem in Haskell?
> Cheers,
> Christian
>

I would check for allocation failure in the C wrapper and return a
status code or error message back to Haskell. Thus the prototype of
the C wrapper might be:

> result_code_t c_create_matrix(t1 arg1, t2 arg2, c_matrix *result);

Then you could either throw a Haskell exception (which is allowed from
pure code - but can only be caught in IO) or do everything under
'Maybe'.

If you expect allocation failure to be rare and exceptional, I would
lean towards the exception. I haven't had the occasion to wrap C
libraries were I expected this sort of thing.

Antoine

> 2011/2/9 Edward Z. Yang <ezy...@mit.edu>
>>
>> Hello Christian,
>>
>> Assuming that the foreign library is based off of mutation on matrices,
>> there's not an easy way to export a nice pure interface to them, because
>> they're not actually persistent: if another thread goes and modifies
>> some pointer which you also have in pure code, referential transparency
>> is broken. ?So you'll have to think carefully about what sorts of
>> guarantees
>> you can (or want) to make to Haskell, and if you can't fulfill them, keep
>> the code in IO (or create your own monad for manipulating matrices).
>>
>> Edward
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>



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

Message: 4
Date: Wed, 9 Feb 2011 13:41:16 -0800
From: Michael Litchard <mich...@schmong.org>
Subject: [Haskell-beginners] question concerning conversion from one
        type to another
To: beginners@haskell.org
Message-ID:
        <AANLkTi=zrggugx4sxfjzjbomjbguw_qed1_kh6pjv...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I'm using Network.Curl, and have to operate on values of type InfoValue.
Now, an InfoValue looks exactly like a [String], and I would like to operate
on it as if it were.
Is the proper approach to convert it to a [String], or would I be using
fmap?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110209/2b0579c2/attachment-0001.htm>

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

Message: 5
Date: Wed, 9 Feb 2011 15:48:26 -0600
From: aditya siram <aditya.si...@gmail.com>
Subject: Re: [Haskell-beginners] question concerning conversion from
        one type to another
To: Michael Litchard <mich...@schmong.org>
Cc: beginners@haskell.org
Message-ID:
        <aanlktikcnz1teftcqycnudouf+4vdrkcdqyiuex8m...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

>From the docs [1] it looks like InfoValue has a few constructors only
one of which (IList) has a [String].

You'll want to pattern-match on InfoValue to extract the [String] like :
f :: InfoValue -> ...
f (IList ss) .... =
f (IString  s) ... =

The second line pattern matches on a IList and 'ss' is the [String] .
-deech

[1] 
http://hackage.haskell.org/packages/archive/curl/latest/doc/html/Network-Curl-Info.html#t:InfoValue
On Wed, Feb 9, 2011 at 3:41 PM, Michael Litchard <mich...@schmong.org> wrote:
> I'm using Network.Curl, and have to operate on values of type InfoValue.
> Now, an InfoValue looks exactly like a [String], and I would like to operate
> on it as if it were.
> Is the proper approach to convert it to a [String], or would I be using
> fmap?
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>



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

Message: 6
Date: Wed, 09 Feb 2011 23:14:55 +0100
From: "." <ch.go...@googlemail.com>
Subject: Re: [Haskell-beginners] Ffi, memory allocation and failure
To: Antoine Latter <aslat...@gmail.com>
Cc: "beginners@haskell.org" <beginners@haskell.org>
Message-ID: <1297289695.3591.1.camel@eddy>
Content-Type: text/plain; charset="UTF-8"

Thanks Antoine and Edward!
I will try the exception in my first go.

Christian

On Wed, 2011-02-09 at 11:26 -0600, Antoine Latter wrote:
> On Wed, Feb 9, 2011 at 8:57 AM, C Gosch <ch.go...@googlemail.com> wrote:
> > Hi Edward, hello to all list members,
> > thank you for your comments, I will keep that in mind. There will be
> > operations on matrices (and other objects) which modify the objects,
> > and those will be in IO or ST, I think.
> > However, I am planning to provide operations with matrices which guarantee
> > that each involved matrix is not changed, but which may return new matrices.
> > All matrices have to be allocated, and that allocation can fail ... how does
> > one usually go about this problem in Haskell?
> > Cheers,
> > Christian
> >
> 
> I would check for allocation failure in the C wrapper and return a
> status code or error message back to Haskell. Thus the prototype of
> the C wrapper might be:
> 
> > result_code_t c_create_matrix(t1 arg1, t2 arg2, c_matrix *result);
> 
> Then you could either throw a Haskell exception (which is allowed from
> pure code - but can only be caught in IO) or do everything under
> 'Maybe'.
> 
> If you expect allocation failure to be rare and exceptional, I would
> lean towards the exception. I haven't had the occasion to wrap C
> libraries were I expected this sort of thing.
> 
> Antoine
> 
> > 2011/2/9 Edward Z. Yang <ezy...@mit.edu>
> >>
> >> Hello Christian,
> >>
> >> Assuming that the foreign library is based off of mutation on matrices,
> >> there's not an easy way to export a nice pure interface to them, because
> >> they're not actually persistent: if another thread goes and modifies
> >> some pointer which you also have in pure code, referential transparency
> >> is broken.  So you'll have to think carefully about what sorts of
> >> guarantees
> >> you can (or want) to make to Haskell, and if you can't fulfill them, keep
> >> the code in IO (or create your own monad for manipulating matrices).
> >>
> >> Edward
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > Beginners@haskell.org
> > http://www.haskell.org/mailman/listinfo/beginners
> >
> >





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

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 32, Issue 26
*****************************************

Reply via email to