[email protected]
[Top] [All Lists]

Re: [Haskell-cafe] Distinct types in a list

Subject: Re: [Haskell-cafe] Distinct types in a list
From: Ozgur Akgun
Date: Thu, 7 Jan 2010 18:44:41 +0000
If I understand you correctly, what you want is very similar to catMaybes

isSuccess' (Success a) = Just a
isSuccess' _ = Nothing

result = catMaybes $ map isSuccess ps

This should do the trick.

2010/1/7 rodrigo.bonifacio <[email protected]>
Hi all,

I have a family of parsers that return either (Success t) or (Fail), using the following data type:

> data ParserResult a = Success a | Fail String
> Âderiving (Read, Show, Eq, Ord)
> isSuccess (Success _) = True
> isSuccess (Fail _) = False
> ...

I want to add the results of different parsers to a list. Such as:

> m1 = parseFirstModel file1 Â -- it returns a ParserResult of t1
> m2 = parseSecondModel file2 Â-- it returns a ParserResult of t2

> ps = [m1, m2]

In such a way that I could write something like:

> if and (map isSuccess ps)
> Âthen process m1 m2
> Âelse ...

Actually, in the real program I have to check more than two input models. However, since Lists do only hold elements of a same type, I couldn't proceed in this way. Which improvements to the ParserResult data type should I wrote in order to proceed as I want to.

Best regards,

Haskell-Cafe mailing list
[email protected]

Ozgur Akgun
Haskell-Cafe mailing list
[email protected]
<Prev in Thread] Current Thread [Next in Thread>