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.  given these types (HFuse), can I share state? (Jon Dowland)
   2. Re:  Beginners Digest, Vol 45, Issue 35 (Lorenzo Bolla)
   3. Re:  given these types (HFuse),   can I share state?
      (Antoine Latter)
   4. Re:  given these types (HFuse),   can I share state?
      (Krzysztof Skrz?tnicki)
   5.  Non ghc specific FRP (using uhc js backend) (Nathan H?sken)


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

Message: 1
Date: Wed, 28 Mar 2012 15:32:26 +0100
From: Jon Dowland <jon+haskell-beginn...@dowland.me>
Subject: [Haskell-beginners] given these types (HFuse), can I share
        state?
To: beginners@haskell.org
Message-ID: <20120328143221.GB20925@debian>
Content-Type: text/plain; charset=utf-8

Hi,

Firstly, this is my first post to this list, I consider myself a Haskell
beginner but this question might be a bit esoteric so please let me know if I'm
better directing this elsewhere.

I'm writing a small fuse-based filesystem[1] using hfuse[2].  I get to write
functions to a defined type.  One of these is 'open', for when the user opens a
file; another is 'read', for when a user invokes the read syscall. Here are the
type signatures:

  fuseOpen :: FilePath -> OpenMode -> OpenFileFlags -> IO (Either Errno fh)

  fuseRead :: FilePath -> fh -> ByteCount -> FileOffset -> IO (Either Errno 
ByteString)

In the case of my filesystem, for a typical work pattern of open, read, read, 
read?;
there's an amount of setup that is required up front (possibly combining two or 
more
files via patches; uncompressing files, etc.) which can be quite expensive.

With my current implementation, I am having to do this work in the read 
function[3],
because I can't figure out a way of doing it in the open function and sharing 
the
state with subsequent reads.  I think this is likely to be a performance issue 
and
I'd prefer to have it done once, in the open function.

I know that there are various 'state' monads, although I've never used them. In
my case the signature for my functions is fixed, but the 'return' type is the
IO monad.  Is there any possibility for me to hide/share state 'through' the IO
monad?


Thanks for your help,


[1] http://jmtd.net/software/rdifffs/
[2] 
http://hackage.haskell.org/packages/archive/HFuse/0.2.4/doc/html/System-Fuse.html
[3] the work takes place within 'rdiffIncrementReadFile', here:
    https://github.com/jmtd/rdifffs/blob/master/rdifffs.lhs#L558


-- 
Jon Dowland




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

Message: 2
Date: Wed, 28 Mar 2012 15:33:45 +0100
From: Lorenzo Bolla <lbo...@gmail.com>
Subject: Re: [Haskell-beginners] Beginners Digest, Vol 45, Issue 35
To: beginners@haskell.org
Message-ID:
        <CADjgTRxqAZ28=gnwhmuqtjozexoyjmkacwagrqt1qz1zxwz...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Or, with a one-liner (inefficient, though):

unique xs = [x | x <- xs, length (filter (== x) xs) == 1]

L.


On Wed, Mar 28, 2012 at 9:38 AM, <franc...@gmx.com> wrote:

>
> Indeed the second snipper contains quite an obvious mistake. Thanks for
> noticing!
>
> It doesn't seem to me it utilises a lambda expression though? You mean the
> '.' operator for chaining function? If that's it, it could be rewritten
>
>
> unique :: [Integer] -> [Integer]
> unique []   = []
> unique (x:xs) | elem x xs   = unique (filter (/= x) xs)
>
>               | otherwise   = x : unique xs
>
>
>
>
>
>
>
>
>  ----- Original Message -----
>
> From: Ramesh Kumar
>
> Sent: 03/28/12 10:14 AM
>
> To: franc...@gmx.com, beginners@haskell.org
>
> Subject: Re: [Haskell-beginners] Beginners Digest, Vol 45, Issue 35
>
>   Thanks Franco, Your (first) solution is the only one which has worked
> so far although it utilizes a lambda expression.
>  The problem is indeed tricky.
>
>
>
>   ------------------------------
> *From:* "franc...@gmx.com" <franc...@gmx.com>
> *To:* beginners@haskell.org
> *Sent:* Wednesday, March 28, 2012 3:39 PM
> *Subject:* Re: [Haskell-beginners] Beginners Digest, Vol 45, Issue 35
>
>  gah sorry I obviously meant to reply to the "Unique integers in a list"
> message
>
>
>
>
>
>  ----- Original Message -----
>  From: franc...@gmx.com
>  Sent: 03/28/12 09:36 AM
>  To: beginners@haskell.org
>  Subject: Re: Beginners Digest, Vol 45, Issue 35
>
>  unique :: [Integer] -> [Integer]
> unique []   = []
> unique (x:xs) | elem x xs   = (unique . filter (/= x)) xs
>               | otherwise   = x : unique xs
>
> -- This is a simpler to read version (albeit inefficient?)
> unique :: [Integer] -> [Integer]
> unique []   = []
> unique (x:xs) | elem x xs   = unique xs
>               | otherwise   = x : unique xs
>
>
>
> _______________________________________________
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120328/46123106/attachment-0001.htm>

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

Message: 3
Date: Wed, 28 Mar 2012 09:58:38 -0500
From: Antoine Latter <aslat...@gmail.com>
Subject: Re: [Haskell-beginners] given these types (HFuse),     can I
        share state?
To: Jon Dowland <jon+haskell-beginn...@dowland.me>
Cc: beginners@haskell.org
Message-ID:
        <CAKjSnQHxDdAJUVWpmxtad4HPheff=ha4oyvwmvgovmbo5it...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Wed, Mar 28, 2012 at 9:32 AM, Jon Dowland
<jon+haskell-beginn...@dowland.me> wrote:
> Hi,
>
> Firstly, this is my first post to this list, I consider myself a Haskell
> beginner but this question might be a bit esoteric so please let me know if 
> I'm
> better directing this elsewhere.
>
> I'm writing a small fuse-based filesystem[1] using hfuse[2]. ?I get to write
> functions to a defined type. ?One of these is 'open', for when the user opens 
> a
> file; another is 'read', for when a user invokes the read syscall. Here are 
> the
> type signatures:
>
> ?fuseOpen :: FilePath -> OpenMode -> OpenFileFlags -> IO (Either Errno fh)
>
> ?fuseRead :: FilePath -> fh -> ByteCount -> FileOffset -> IO (Either Errno 
> ByteString)
>
> In the case of my filesystem, for a typical work pattern of open, read, read, 
> read?;
> there's an amount of setup that is required up front (possibly combining two 
> or more
> files via patches; uncompressing files, etc.) which can be quite expensive.
>
> With my current implementation, I am having to do this work in the read 
> function[3],
> because I can't figure out a way of doing it in the open function and sharing 
> the
> state with subsequent reads. ?I think this is likely to be a performance 
> issue and
> I'd prefer to have it done once, in the open function.
>

I've never used hfuse, but can't you put the state you need in the
'fh' type you pass back from 'fuseOpen'? In your case it is the 'HT'
type.

I'm imagining something like:

> data HT = HT (IORef HandleState)

Antoine



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

Message: 4
Date: Wed, 28 Mar 2012 18:14:29 +0200
From: Krzysztof Skrz?tnicki <gte...@gmail.com>
Subject: Re: [Haskell-beginners] given these types (HFuse),     can I
        share state?
To: Jon Dowland <jon+haskell-beginn...@dowland.me>
Cc: beginners@haskell.org
Message-ID:
        <CAM7aEVHZD=-eKCzQg27-S2PEGfxGHFQbRLT9Vmk14c=iezx...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

You can create shared state prior to making FuseOperations. Define
functions like this:

mkFuseOperations :: SharedState -> FuseOperations MyHandleType
mkSharedState :: IO SharedState

The type SharedState can be anything you like, similarly to MyHandleType.

type SharedState = IORef String
type MyHandleType = Handle

Example implementation:

mkSharedState name = newIORef name
mkFuseOperations shared = defaultFuseOps {
       fuseInit = do { print "FUSE INIT MODULE"; print =<< readIORef shared
},
       fuseDestroy = do { print "FUSE DESTROY MODULE"; print =<< readIORef
shared };  }

main = do
  ss <- mkSharedState "my fuse module"
  let fo = mkFuseOperations ss
  fuseMain fo defaultExceptionHandler


Best regards,
Krzysztof Skrz?tnicki


On Wed, Mar 28, 2012 at 16:32, Jon Dowland <jon+haskell-beginn...@dowland.me
> wrote:

> Hi,
>
> Firstly, this is my first post to this list, I consider myself a Haskell
> beginner but this question might be a bit esoteric so please let me know
> if I'm
> better directing this elsewhere.
>
> I'm writing a small fuse-based filesystem[1] using hfuse[2].  I get to
> write
> functions to a defined type.  One of these is 'open', for when the user
> opens a
> file; another is 'read', for when a user invokes the read syscall. Here
> are the
> type signatures:
>
>  fuseOpen :: FilePath -> OpenMode -> OpenFileFlags -> IO (Either Errno fh)
>
>  fuseRead :: FilePath -> fh -> ByteCount -> FileOffset -> IO (Either Errno
> ByteString)
>
> In the case of my filesystem, for a typical work pattern of open, read,
> read, read?;
> there's an amount of setup that is required up front (possibly combining
> two or more
> files via patches; uncompressing files, etc.) which can be quite expensive.
>
> With my current implementation, I am having to do this work in the read
> function[3],
> because I can't figure out a way of doing it in the open function and
> sharing the
> state with subsequent reads.  I think this is likely to be a performance
> issue and
> I'd prefer to have it done once, in the open function.
>
> I know that there are various 'state' monads, although I've never used
> them. In
> my case the signature for my functions is fixed, but the 'return' type is
> the
> IO monad.  Is there any possibility for me to hide/share state 'through'
> the IO
> monad?
>
>
> Thanks for your help,
>
>
> [1] http://jmtd.net/software/rdifffs/
> [2]
> http://hackage.haskell.org/packages/archive/HFuse/0.2.4/doc/html/System-Fuse.html
> [3] the work takes place within 'rdiffIncrementReadFile', here:
>    https://github.com/jmtd/rdifffs/blob/master/rdifffs.lhs#L558
>
>
> --
> Jon Dowland
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120328/ab64c808/attachment-0001.htm>

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

Message: 5
Date: Wed, 28 Mar 2012 21:54:30 +0200
From: Nathan H?sken <nathan.hues...@posteo.de>
Subject: [Haskell-beginners] Non ghc specific FRP (using uhc js
        backend)
To: Beginners <beginners@haskell.org>
Message-ID: <4bdf3429f6bafe174e03e6f5c607f...@posteo.de>
Content-Type: text/plain; charset=UTF-8; format=flowed

Hi,

I am currently informing myself about FRP. Looking at the Elerea paper 
(http://sgate.emt.bme.hu/documents/patai/publications/PataiWFLP2010.pdf) 
I read that it is ghc specific because of mutable references.
I am trying to use the js backend of uhc and that does not support 
this.
I have tried to use other FRP libraries with uhc (by compiling a file 
which does nothing but import the library) and all failed because of 
something missing in Control.Concurrent.

So I am wondering: Is it a property FRP that it needs something like 
mutable references for an efficient implementation.
Is there a FRP library that can be used (or can be changed so that it 
can be used) with uhc and its js backend?

Thanks!
Nathan





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

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


End of Beginners Digest, Vol 45, Issue 37
*****************************************

Reply via email to