Questions tagged [infix-operator]

Infix operators placed between the operands they act on (e.g. 2 + 2).

107 questions
23
votes
1 answer

How to check Haskell infix operator precedence

I can see the type of an infix operator in GHCi with :t like so: >:t (.) (.) :: (b -> c) -> (a -> b) -> a -> c How can i see the operator precedence in GHCi? is that possible? Also, bonus question, is there a way to see the source of these…
Adam Gordon Bell
  • 3,083
  • 2
  • 26
  • 53
17
votes
1 answer

Assigning a value to a list item using `assign()`

A little bit of context first... I've written an infix function that in essence replaces the idiom x[[length(x) +1]] <- y ..or simply x <- append(x, y) for vectors. Here it is: `%+=%` <- function(x, y) { xcall <- substitute(x) xobjname <-…
Dominic Comtois
  • 10,230
  • 1
  • 39
  • 61
13
votes
1 answer

Can I make haskell GADT data constructor infix in derived Show?

Consider two data declarations: {-# LANGUAGE GADTs #-} data X = Int `Y` Int deriving Show data Z where W :: Int -> Int -> Z deriving Show main = do print (1 `Y` 2) print (3 `W` 4) Running the above program produces: 1…
Alexander Gorshenev
  • 2,769
  • 18
  • 33
12
votes
1 answer

Defining an infix operator for use within a formula

I'm trying to create a more parsimonious version of this solution, which entails specifying the RHS of a formula in the form d1 + d1:d2. Given that * in the context of a formula is a pithy stand-in for full interaction (i.e. d1 * d2 gives d1 + d2 +…
MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
12
votes
1 answer

Why is f <$> g <$> x equivalent to (f . g) <$> x although <$> is not right-associative?

Why is f <$> g <$> x equivalent to (f . g) <$> x although <$> is not right-associative? (This kind of equivalence is valid in a popular idiom with plain $, but currently $ is right-associative!) <*> has the same associativity and precedence as <$>,…
12
votes
2 answers

How to use ** for exponents using @infix func **( )?

I want to use ** to overload an exponent function. I works if I use something like "^" but the python way of doing is ** and I would like to use that with Swift. Any way to do that? error: Operator implementation without matching operator…
Chéyo
  • 9,107
  • 9
  • 27
  • 44
11
votes
1 answer

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…
PyRulez
  • 10,513
  • 10
  • 42
  • 87
11
votes
2 answers

Haskell: Why aren't infix type constructors allowed?

In the Haskell 98 report, I found this: The syntax for Haskell type expressions is given above. Just as data values are built using data constructors, type values are built from type constructors. As with data constructors, the names of type…
AJF
  • 11,767
  • 2
  • 37
  • 64
11
votes
6 answers

Is it possible to define an infix function?

Is it possible to define my own infix function/operator in CoffeeScript (or in pure JavaScript)? e.g. I want to call a foo b or a `foo` b instead of a.foo b or, when foo is global function, foo a, b Is there any way to do this?
10
votes
1 answer

Raku infix operator in method-like syntax

In Raku, infix operators can be used like functions, e.g.: 1 + 2 ; # 3 infix:<+>(1, 2) ; # 3 [+] 1, 2 ; # 3 Prefix operators can be used with method-like syntax (methodop): -1 ; # -1 1.:<-> ; # -1 So, (rather…
mykhal
  • 19,175
  • 11
  • 72
  • 80
10
votes
3 answers

Scala match decomposition on infix operator

I'm trying to understand the implementation of Lists in Scala. In particular I'm trying to get my head around how you can write match expressions using an infix operator, for example: a match { case Nil => "An empty list" case x :: Nil => "A…
thatismatt
  • 9,832
  • 10
  • 42
  • 54
8
votes
1 answer

How does R evaluate these weird expressions?

I was trying to make Python 3-style assignment unpacking possible in R (e.g., a, *b, c = [1,2,3], "C"), and although I got so close (you can check out my code here), I ultimately ran into a few (weird) problems. My code is meant to work like this: a…
Zeke
  • 617
  • 1
  • 6
  • 15
8
votes
1 answer

Why can't I chain several Scala infix method calls

I am working on a DSL and I've run into a problem with using methods as infix operators in a chain. I'll just try to explain it with some code. I have a trait Term and case classes Literal and Variable extending it. I want to construct a list of…
Rouzbeh Delavari
  • 179
  • 1
  • 2
  • 9
8
votes
1 answer

User-defined infix operators

It is easy to introduce new infix operators in C++ // User-defined infix operator framework template struct LeftHelper { const LeftOperand& leftOperand; const Operation& operation; …
n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
7
votes
1 answer

How do I use ?: in Swift?

I love this syntax in Objective-C, where a question mark and colon let you use a backup value: NSString const name = [self getName] ?: @"backup"; and I want to use the same in Swift, but I get this when I try: Is there any way to do this in Swift?…
Ky -
  • 30,724
  • 51
  • 192
  • 308
1
2 3 4 5 6 7 8