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

Christian Maeder Christian.Maeder at dfki.de
Thu Jan 7 14:02:15 EST 2010


You could cast your parser result "a" to Dynamic using
Data.Dynamic.toDyn (and derive Typeable instances for all involved types).

http://www.haskell.org/ghc/docs/latest/html/libraries/base-4.2.0.0/Data-Dynamic.html

Using an existential types may be another alternative.

Cheers Christian

rodrigo.bonifacio schrieb:
> 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,
> 
> Rodrigo. 
>  


More information about the Haskell-Cafe mailing list