Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give infixities to operators in lambda?

For example, this does not type check

\cons nil -> 5 `cons` 3 `cons` nil

nor does this

\(#) -> 5 # 3 # nil

Although both of these do

\cons nil -> 5 `cons` nil
\(#) nil -> 5 # nil

Is there a way to assign infixites to operators in lambdas. I tried

infixr 5 #
foo = \(#) nil -> 5 # 3 # nil

which gives an error for no definition of # and

foo = \(infixr 5 #) nil -> 5 # 3 # nil

which is just a syntax error.

What can I do?

like image 941
PyRulez Avatar asked Dec 05 '15 18:12

PyRulez


1 Answers

Fixity declarations can be local but must accompany definitions, so you'd have to write something like

foo cons nil = 'a' # 'b' # nil
  where (#) = cons
        infixr 5 #

or

foo = \cons nil -> let (#) = cons; infixr 5 # in 'a' # 'b' # nil

etc.

like image 90
Reid Barton Avatar answered Oct 31 '22 10:10

Reid Barton