Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/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:  best way to code this~~ ([email protected])
   2.  Command line interface programming (Dananji Liyanage)


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

Message: 1
Date: Sun, 31 May 2015 08:02:29 -0700
From: <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] best way to code this~~
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

On Sun, 31 May 2015 05:17:10 +0000
Alex Hammel <[email protected]> wrote:

> f as alist = [ b | (a, b) <- alist, a `elem` as ]
> 
> perhaps?

perhaps.  i have no idea how that works.  but don't spoil it for me though, i'm 
going to go of and study it :-)

@Chaddai . this is for very small lists, so optimization in the form of sorting 
and binary lookup is definitely not worth the effort.


Here's what I finally wrote.  partitionMaybe is a modified version of partition 
from the List library.

unsure what the ~(ts, fs) syntax is though, removing the `~` doesn't seem to 
matter.

this seems fairly clean. i noticed that partition simply uses foldr.  it looks 
like select is just a helper so that partition isn't cluttered.  i'm unsure why 
select was broken out as a separate function instead of just being in a where 
clause.  possibly to be able to assign it a an explicit type signature ?  more 
likely it has something to do with the fact that in the library partition is 
declared inline.

extract :: [(String,b)] -> [String] -> ([b], [String])
extract alist l =
  let inList s = lookup (uppercase s) alist
      (l1, l2) = partitionMaybe inList l
  in
   (l1, l2)

partitionMaybe :: (a -> Maybe b) -> [a] -> ([b],[a])
partitionMaybe p xs = foldr (select p) ([],[]) xs

select :: (a -> Maybe b) -> a -> ([b], [a]) -> ([b], [a])
select p x ~(ts,fs) | isJust y = ((fromJust y):ts,fs)
                    | otherwise = (ts, x:fs)
  where
    y = p x


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

Message: 2
Date: Mon, 1 Jun 2015 15:41:54 +0530
From: Dananji Liyanage <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Command line interface programming
Message-ID:
        <CAAPsY8z063srqTJCn2gV6mp9a=i8ww4pTH-7Cp=qh14a1ro...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi All,

I'm in the process of learning Haskell, and I need to write a command line
interface program which can interact with the user.

Right now, I have a sample program written using 'System.Console.Haskeline'
package.

Can someone please give me some additional material, which I can read on
with respect to this?

Thanks in advance!

-- 
Regards,
Dananji Liyanage
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150601/078de08a/attachment-0001.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 84, Issue 1
****************************************

Reply via email to