Send Beginners mailing list submissions to
        beginners@haskell.org

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
        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:  Applying a function to two lists (Francesco Ariis)
   2.  Handling failed output (Matt Williams)
   3. Re:  Handling failed output (Imants Cekusins)


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

Message: 1
Date: Sat, 23 Apr 2016 15:42:06 +0200
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Applying a function to two lists
Message-ID: <20160423134206.ga1...@casa.casa>
Content-Type: text/plain; charset=us-ascii

On Sat, Apr 23, 2016 at 08:50:32AM +0000, Matt Williams wrote:
> Thanks a lot for this.
> 
> Just to clarify (and ignoring the flip, which I can solve by rewriting the
> checkNum function) - is this an example of currying?

Example of partial application! Currying is when you have a function like:

    f :: (a, b) -> c

and transform it to:

    g :: a -> b -> c

Open ghci and play a bit with `curry` and `uncurry` to get the idea!


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

Message: 2
Date: Sat, 23 Apr 2016 21:59:10 +0100
From: Matt Williams <matt.williams45...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Handling failed output
Message-ID: <571be21e.6050...@gmail.com>
Content-Type: text/plain; charset=utf-8; format=flowed

Dear All,

I am trying to work out how to handle a function that might return 
different types of output. I assume I need to use either Maybe or 
Either, but I can't quite get it to work.

At the moment, I have some function:

checkNum3 :: Int -> Int -> (Int,Int)
checkNum3 a b = if check a b then (a,b)
                 else (a,-1)

checkLists :: [Int] -> Int -> [(Int,Int)]
checkLists a b = map (checkNum3 b) a

checkAll3 :: [Int] -> [Int] -> [(Int,Int)]
checkAll3 a b = concat (map (checkLists a) b)

However, I know that checkNum3 isn't a good function - it uses setting 
the second element of the tuple to -1 to signal failure, which is 
obviously a recipe for problems later on. However, I want to return 
either a pair of integers, or a single integer.

Any advice would be appreciated.

Thanks,
Matt


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

Message: 3
Date: Sat, 23 Apr 2016 23:05:05 +0200
From: Imants Cekusins <ima...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Handling failed output
Message-ID:
        <cap1qinbwnlwek6rhn97ghy4_cg8m1cty_6w2gbgxtyt-u4+...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hello Matt,

Either Int (Int,Int) might work.

Left ... by convention indicates 'other' result.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160423/e7a4dfa6/attachment-0001.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

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

Reply via email to