Cannot define intermediate operator bb

Asked 2 years ago, Updated 2 years ago, 110 views

I'm sorry to bother you so often.
I have a question about Haskell.

by & expression
True&&_=_
False &_= False

The problem is to express with a conditional expression.

(bb)::Bool->a->b
x bby = if x == True then else x

When I compiled the above program, I got the following error

 enzan.hs:1:1:error:
Invalid type signature: (bb)::...
Should be of form <variable>::<type>
  |
1 | (bb)::Bool->a->b||Bool
  | ^^^^

I'm not sure what's wrong with the program, but please let me know.

haskell

2022-09-30 15:46

2 Answers

bb is used like an intermediate operator, but the intermediate operator must be a symbol.

For example, modifying to define .&. eliminates errors.

 (.&.)::Bool->Bool->Bool
x.&&.y = if x then else x


2022-09-30 15:46

This is an answer to the question of the commenter.

The error message is

I expected type b, but I couldn't match it because it was actually Bool.
b is a type variable bound by type signature (.&.)::forall a b.Bool->a->b.

I mean, actually

 x.&.y = if x then else x

By definition, (.&.) has no other type than Bool->Bool->Bool.
Conversely, consider whether you can define an operator with the first type signature.
Type Signature (.&.): According to Bool->a->b, in the formula x.&y, the value of x is of any type, the type of y is of any type, and the type of whole expression (x.&y) is of any type (even if it is different from x).


2022-09-30 15:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.