
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...

On Thu, Nov 10, 2011 at 11:37 PM, kolli kolli
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
The problem is clearly not that you're using (&&) (which is the correct way to have two conditions in one guard) but that "typing capGama t1" is of type "Maybe Type" while TypeBool is of type "Type", so you can't compare them with an (==), maybe you meant to use "Just TypeBool" ? -- Jedaï

I have to feame the code saying in IF t1 t2 t3
If t1 has type x and if type of t2 == type of t3 then return type of t2 or
t3
On Thu, Nov 10, 2011 at 3:51 PM, Chaddaï Fouché
On Thu, Nov 10, 2011 at 11:37 PM, kolli kolli
wrote: 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
The problem is clearly not that you're using (&&) (which is the correct way to have two conditions in one guard) but that "typing capGama t1" is of type "Maybe Type" while TypeBool is of type "Type", so you can't compare them with an (==), maybe you meant to use "Just TypeBool" ?
-- Jedaï

On Thu, 10 Nov 2011 15:55:48 -0700, kolli kolli
I have to feame the code saying in IF t1 t2 t3
If t1 has type x and if type of t2 == type of t3 then return type of t2 or t3
As Chaddaï said, the result of a call to typing has type Maybe Type while TypeBool has type Type, so you would have to compare the result with Just TypeBool, and not just TypeBool. The same applies to "where x = typing capGamma t3". Here x already has type Maybe Type, so passing it to Just would give you a value of type Maybe (Maybe Type). This can be resolved by returning x directly in this case: ... | typing capGama t1 == TypeBool && typing capGama t2 == x = x A minor stylistic comment: It's common to write `Just TypeBool' instead of `Just(TypeBool)', since a constructor is really just a (special kind of) function. Cheers, Daniel

On Fri, 11 Nov 2011 00:02:56 -0500, Brent Yorgey
On Fri, Nov 11, 2011 at 01:21:58AM +0100, Daniel Schoepe wrote:
On Thu, 10 Nov 2011 15:55:48 -0700, kolli kolli
wrote: with Just TypeBool, and not just TypeBool.
An unfortunate case of significant case. ;)
Yeah, now that you mention it, this was probably not the best way to put it. :) Cheers, Daniel
participants (4)
-
Brent Yorgey
-
Chaddaï Fouché
-
Daniel Schoepe
-
kolli kolli