[Haskell-cafe] do we have something like isDefined or isNull in Haskell?

Bryan Burgers bryan.burgers at gmail.com
Thu Jun 15 16:26:57 EDT 2006


Vladimir,

I think you forgot to put Haskell-cafe as a recipient of this email,
so first I'll repost what you wrote.

On 6/15/06, Vladimir Portnykh <vportnykh at hotmail.com> wrote:
> many thanks. i have the follwoing code:
>
> module MyType (DataContainer(..)) where
> import Maybe
> data DataContainer =
>     MyType {
>             date :: [Maybe Double],
>                         weight ::[Maybe Double],
>                         height ::[Maybe Double]
>            }
>             deriving (Eq, Ord, Show)
>
> myType =  MyType {
>             date =
> [38548,38562,38576,38590,38604,38618,38632,38646,38660,38674],
>                         weight = [],
>                         height = []
>                         }
>
> reportProblem = if isJust (height myType  !! (length (date myType) - 1))
> then 0 else 1
>
>
> it failed to compiled saying "No instance for (Num (Maybe Double)) arising
> from the literal 38674 .

After reading your code for a while, I still don't know if I quite
understand.  Can you explain exactly what you are trying to do?

My thought is that maybe you just want a list of objects, since you
are indexing height at the same index as date.  Then you just want a
list of the structures that Duncan described.

myObjects = [default {weight = 3.2}, default {weight = 7.9, date=38458},...]

If not, hopefully somebody a little more knowledgable than I can help you.

Bryan


More information about the Haskell-Cafe mailing list