Skip to content

Instantly share code, notes, and snippets.

@rtoal
Created June 18, 2017 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtoal/f45404d00e1d8c8329a92027865e5538 to your computer and use it in GitHub Desktop.
Save rtoal/f45404d00e1d8c8329a92027865e5538 to your computer and use it in GitHub Desktop.
Is [-8] < 0?

Clojure

user=> (< [-8] 0)

ClassCastException clojure.lang.PersistentVector cannot be cast to java.lang.Number

Python 2 (BOOOOOOOOOOO)

>>> [-8] < 0
False

Python 3 (THANK YOU GvR!! GO HOME PYTHON 2 YOU SUCK)

>>> [-8] < 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'list' and 'int'

Ruby

>> [-8] < 0
NoMethodError: undefined method `<' for [-8]:Array

Lua

> print({-8} < 0)
stdin:1: attempt to compare table with number

Julia

julia> [-8] < 0
ERROR: MethodError: no method matching isless(::Array{Int64,1}, ::Int64)

Elm

> [-8] < 0
-- TYPE MISMATCH --------------------------------------------- repl-temp-000.elm

The right side of (<) is causing a type mismatch.

3|   [-8] < 0
            ^
(<) is expecting the right side to be a:

    List number

But the right side is:

    number

Hint: With operators like (<) I always check the left side first. If it seems
fine, I assume it is correct and check the right side. So the problem may be in
how the left and right arguments interact.

JavaScript (YOU KNEW WHAT THIS WAS GOING TO DO RIGHT?)

> [-8] < 0
true

Swift

  1> [-8] < 0
error: repl.swift:1:6: error: binary operator '<' cannot be applied to operands of type '[Int]' and 'Int'

Standard ML

- [~8] < 0;
! Toplevel input:
! [~8] < 0;
!        ^
! Type clash: expression of type
!   int
! cannot have type
!   int list

Erlang

1> [-8] < 0.
false

Scala

scala> List(-8) < 0
<console>:12: error: value < is not a member of List[Int]

CoffeeScript (Well it is just JavaScript)

coffee> [-8] < 0
Expression assignment to _ now disabled.
true

Haskell

Prelude> [-8] < 0

<interactive>:13:1: error:
    • Ambiguous type variable ‘t0’ arising from a use of ‘<’
      prevents the constraint ‘(Ord t0)’ from being solved.
      Probable fix: use a type annotation to specify what ‘t0’ should be.
      These potential instances exist:
        instance Ord Ordering -- Defined in ‘GHC.Classes’
        instance Ord Integer
          -- Defined in ‘integer-gmp-1.0.0.1:GHC.Integer.Type’
        instance Ord a => Ord (Maybe a) -- Defined in ‘GHC.Base’
        ...plus 22 others
        ...plus five instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the expression: [- 8] < 0
      In an equation for ‘it’: it = [- 8] < 0

<interactive>:13:2: error:
    • Ambiguous type variable ‘t0’ arising from a use of syntactic negation
      prevents the constraint ‘(Num t0)’ from being solved.
      Probable fix: use a type annotation to specify what ‘t0’ should be.
      These potential instances exist:
        instance Num Integer -- Defined in ‘GHC.Num’
        instance Num Double -- Defined in ‘GHC.Float’
        instance Num Float -- Defined in ‘GHC.Float’
        ...plus two others
        (use -fprint-potential-instances to see them all)
    • In the expression: - 8
      In the first argument of ‘(<)’, namely ‘[- 8]’
      In the expression: [- 8] < 0

<interactive>:13:8: error:
    • No instance for (Num [t0]) arising from the literal ‘0’
    • In the second argument of ‘(<)’, namely ‘0’
      In the expression: [- 8] < 0
      In an equation for ‘it’: it = [- 8] < 0

Idris

Idris> [-8] < 0
List Integer is not a numeric type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment