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.  maybe use for functors or arrows? (Michael Mossey)
   2. Re:  maybe use for functors or arrows? (Stephen Tetley)
   3. Re:  maybe use for functors or arrows? (Stephen Tetley)
   4.  Re: maybe use for functors or arrows? (Heinrich Apfelmus)
   5. Re:  System.Process.createProcess [solved] (John Obbele)
   6. Re:  Re: maybe use for functors or arrows? (Brent Yorgey)


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

Message: 1
Date: Sat, 26 Jun 2010 22:58:07 -0700
From: Michael Mossey <[email protected]>
Subject: [Haskell-beginners] maybe use for functors or arrows?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Is there a way to write the function

process :: [(Location,Item)] -> [(Location,ValuableItem)]


given a function indicating which Item's to keep

transform :: Item -> Maybe ValuableItem

using functors and arrows? The value for location stays with any item that 
is kept.

What I have is

process inp = catMaybes (map g inp)
   where g (l,i) = case transform i of
     Nothing -> Nothing
     Just v  -> Just (l,v)

This looks like an arrow situation to me because you want to make a 
function that acts on the second value in a tuple, and a little bit like a 
Maybe functor.

Thanks,
Mike




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

Message: 2
Date: Sun, 27 Jun 2010 08:38:31 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] maybe use for functors or arrows?
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi Michael

The /case transform i of .../ code should be able to be rephrased with
fmap as it is "putting back" the first element of the tuple if
/transform/ produces a (Just) value.

fmap (\a -> (a,v))

Personally, I would look to avoiding building the list of type ::Maybe
(Location,ValuableItem) during the first traversal (via map) to later
filter them out with a second traversal via catMaybes.

The optimization technique "stream fusion" can often collapse
compositions of list functionals (map, filter, etc). into one
traversal. But it isn't available by default - you have to install the
stream-fusion library. Also a composition of functionals isn't
necessarily clearer than a direct implementation.

Best wishes

Stephen


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

Message: 3
Date: Sun, 27 Jun 2010 08:46:05 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] maybe use for functors or arrows?
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On 27 June 2010 08:38, Stephen Tetley <[email protected]> wrote:

>
> fmap (\a -> (a,v))
>

Likely, that fmap is the wrong way round:

fmap (\a -> (l,a))

(The type checker would have spotted the mistake in the really code...)


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

Message: 4
Date: Sun, 27 Jun 2010 09:59:42 +0200
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: maybe use for functors or arrows?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

Michael Mossey wrote:
> Is there a way to write the function
> 
> process :: [(Location,Item)] -> [(Location,ValuableItem)]
> 
> 
> given a function indicating which Item's to keep
> 
> transform :: Item -> Maybe ValuableItem
> 
> using functors and arrows? The value for location stays with any item 
> that is kept.
> 
> What I have is
> 
> process inp = catMaybes (map g inp)
>   where g (l,i) = case transform i of
>     Nothing -> Nothing
>     Just v  -> Just (l,v)
> 
> This looks like an arrow situation to me because you want to make a 
> function that acts on the second value in a tuple, and a little bit like 
> a Maybe functor.

    import Control.Arrow ((***))

    process =
       catMaybes . map (uncurry (liftM2 (,)) . (return *** transform))

Whether this is more readable is another question.


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com



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

Message: 5
Date: Sun, 27 Jun 2010 13:05:19 +0200
From: John Obbele <[email protected]>
Subject: Re: [Haskell-beginners] System.Process.createProcess [solved]
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Sat, Jun 26, 2010 at 08:59:01PM -0400, Brandon S Allbery KF8NH wrote:
> On 6/26/10 18:57 , John Obbele wrote:
> > After digging things a little, it seems I am messing with the
> > System.Process.createProcess function : none of my spawned
> > process terminates and eventually my OS freezes.
> 
> You need to reap zombies manually; take a look at
> System.Process.waitForProcess.  (On POSIX-ish systems, including Linux, you
> can use the signal handling functions to auto-reap; on Linux simply setting
> SIGCHLD to SIG_IGN is good enough, but other systems (*BSD, OSX) require you
> to also set the SA_NOCLDWAIT flag and for portability you should include it.
>  (Which, I note, doesn't seem to be supported in System.Posix.Signals.  O
> Haskell gods:  Bug?)

Oki, I've test with waitForProcess and it's working fine. Thanks
for your help :)

And concerning the signals part, I've never heard of managing
child processes with them. I will go reread some docs about
it, I may learn some new interesting things today ...

regards,
/john


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

Message: 6
Date: Sun, 27 Jun 2010 14:36:05 +0100
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Re: maybe use for functors or arrows?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Sun, Jun 27, 2010 at 09:59:42AM +0200, Heinrich Apfelmus wrote:
> Michael Mossey wrote:
>> Is there a way to write the function
>>
>> process :: [(Location,Item)] -> [(Location,ValuableItem)]
>>
>>
>> given a function indicating which Item's to keep
>>
>> transform :: Item -> Maybe ValuableItem
>>
>> using functors and arrows? The value for location stays with any item that 
>> is kept.
>>
>> What I have is
>>
>> process inp = catMaybes (map g inp)
>>   where g (l,i) = case transform i of
>>     Nothing -> Nothing
>>     Just v  -> Just (l,v)
>>
>> This looks like an arrow situation to me because you want to make a 
>> function that acts on the second value in a tuple, and a little bit like a 
>> Maybe functor.
>
>    import Control.Arrow ((***))
>
>    process =
>       catMaybes . map (uncurry (liftM2 (,)) . (return *** transform))

One could also do

  process = catMaybes . map (sequenceA . second transform)

where 

  Data.Traversable.sequenceA :: (Traversable t, Applicative f) => t (f a) -> f 
(t a)

is used to "lift" the Maybe from the inside of the tuple to apply to
the whole tuple, specifically

  sequenceA :: (a, Maybe b) -> Maybe (a,b)

Unfortunately this will not work without a Traversable instance for
((,) a), which doesn't already exist, but it ought to, and it's easy
to make:

  import Data.Foldable
  import Data.Traversable

  instance Foldable ((,) a) where
    foldMap = foldMapDefault

  instance Traversable ((,) a) where
    sequenceA (a,fb) = fmap ((,) a) fb

-Brent

>
> Whether this is more readable is another question.
>
>
> Regards,
> Heinrich Apfelmus
>
> --
> http://apfelmus.nfshost.com
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners


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

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


End of Beginners Digest, Vol 24, Issue 38
*****************************************

Reply via email to