[Haskell-cafe] Missing a "Deriving"?
michael rice
nowgate at yahoo.com
Sun May 31 00:46:56 EDT 2009
I figured out the [[Int]] case for myself, but hadn't considered the Failure case. Thanks.
In function "searchAll", given a calling context Failable [Int], for the line
where search' [] = failure "no path"
"failure" would be "Fail", a constructor that takes a String. Right?
But using either of the other two contexts, where failure equals either const Nothing or const [] it would seem like that same string argument "no path" would be passed to either Nothing or [], which doesn't make any sense. Explanation?
Michael
--- On Sat, 5/30/09, David Menendez <dave at zednenem.com> wrote:
From: David Menendez <dave at zednenem.com>
Subject: Re: [Haskell-cafe] Missing a "Deriving"?
To: "michael rice" <nowgate at yahoo.com>
Cc: "Miguel Mitrofanov" <miguelimo38 at yandex.ru>, haskell-cafe at haskell.org
Date: Saturday, May 30, 2009, 9:33 PM
On Sat, May 30, 2009 at 9:00 PM, michael rice <nowgate at yahoo.com> wrote:
> That works. but it gives just a single solution [1,2,3] when there are
> supposed to be two [[1,2,3],[1,4,3]]. Of course the code in YAHT may be in
> error.
Works for me.
*Main> searchAll g 1 3 :: [[Int]]
[[1,2,3],[1,4,3]]
*Main> searchAll g 1 3 :: Maybe [Int]
Just [1,2,3]
*Main> searchAll g 1 3 :: Failable [Int]
Success [1,2,3]
> Also, how the heck does Haskell decide which "success", "failure",
> "augment", and "combine" to use in function "searchAll", since there are
> five possibilities.
*Main> :t searchAll
searchAll :: (Computation c) => Graph t t1 -> Int -> Int -> c [Int]
The way searchAll is written, the choice of which functions to use
depends on the type variable c. That's determined by the calling
context of searchAll, which is why you need to provide a type
signature when using it at the GHCi command line.
--
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090531/c1dafa8b/attachment.html
More information about the Haskell-Cafe
mailing list