While this function example works by declaring type A implicitly between brackets,

if_then_else : {A : Set} -> Bool -> A -> A -> A
if true  then x else y = x
if false then x else y = y

I'm struggling to understand how to write the body of this function that accepts the type argument explicitly like so:

if_then_else : (A : Set) -> Bool -> A -> A -> A

1 Answer 1


Well, the function name is still just a function name:

if_then_else : (A : Set) -> Bool -> A -> A -> A
if_then_else A true  t f = t
if_then_else A false t f = f

If you want to use the distfix syntax, you fit parameters into the underscores on the LHS. If there are parameters left over, they don't distribute in and stay put (with extra parentheses if needed). After all, the point of definition by equations is that the LHSs of the definition look like the usages of the defined object, so the LHS follows the usual syntax for function application.

if_then_else : (A : Set) -> Bool -> A -> A -> A
(if A then true  else t) f = t
(if A then false else t) f = f

This syntax is, of course, terrible. Perhaps you meant to also change the name?

into_if_then_else : (A : Set) -> Bool -> A -> A -> A
into A if true  then t else f = t
into A if false then t else f = f

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.