[Haskell-beginners] guards

kolli kolli nammukolli04 at gmail.com
Thu Nov 10 23:37:17 CET 2011


Hi,,

I am new to use ..plz bare with me..

How do we write two conditions using guards

suppose if we have a if condition if t1 t2 t3

typing :: TypingContext -> Term -> Maybe Type
--the typing relation
typing capGamma (Var x) = contextLookup x capGamma
typing capGama Tru = Just(TypeBool)
typing capGama Fls = Just(TypeBool)
typing capGama Zero = Just(TypeBool)
typing capGama (Succ t) = typing capGama t
typing capGama (Pred t) = typing capGama t
typing capGama (IsZero t) = typing capGama t
typing capGama (If t1 t2 t3)
  | typing capGama t1 == TypeBool && typing capGama t2 == x    = Just(x)
  | otherwise =  Nothing
 where x = typing capGama t3


its giving me  error

    Couldn't match expected type `Maybe Type'
           against inferred type `Type'
    In the second argument of `(==)', namely `TypeBool'
    In the first argument of `(&&)', namely
        `typing capGama t1 == TypeBool'
    In the expression:
            typing capGama t1 == TypeBool && typing capGama t2 == TypeBool

 how can i give two conditions in a single guard...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20111110/9a514ee6/attachment.htm>


More information about the Beginners mailing list