Ticket #174 (closed defect: fixed)

Opened 7 years ago

Last modified 7 years ago

Type mismatch during unification

Reported by: erikd Owned by: erikd
Priority: blocker Milestone: 0.1.3
Component: Source Parser Version:
Keywords: Cc:


Very simple code:

-- Spaces around '-' works correctly.
fun1 n = n - 1

-- This results in a type unification error.
fun2 n = n-1

main ()
 = do	println $ show $ fun1 10
 	println $ show $ fun2 10

fails to compile with:

    Type mismatch during unification.
          cannot match: *348 $357
                  with: *361 %362

              the use of: fun2
                 at type: *348 $357
                      at: ./Main.ds:10:25

        conflicts with, 
          literal value 10i32
                 of type: *361 %362
                      at: ./Main.ds:10:30

Suspect this is actually a parser error.

Change History

Changed 7 years ago by erikd

  • owner set to erikd
  • status changed from new to assigned

Changed 7 years ago by erikd

On the mailing list, Ben said:

The way this is currently supposed to work is:

-- Subraction
fun1 n = n - 1

-- Subtraction
fun2 n = n- 1

-- n applied to integer -1
fun3 n = n -1

-- n applied to integer -1
fun4 n = n-1

In C we can do:

  f(1, 2, -3, -4)

But currently in Haskell it's:

  f 1 2 (-3) (-4)

But we the above rules we can have:

  f 1 2 -3 -4

This way function application can always be seen as "overloading the space character" and '-' followed by digits is always a negative number.

I originally based this on a proposal for Haskell', but I see the proposers have had second thoughts. I agree that not having "n-1" mean "n minus one" is probably too confusing for its own good. Probably better to do what Haskell does here, seeming how we're stealing most of its other syntax...

There's more background at:

Changed 7 years ago by erikd

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in:

Mon Mar 8 21:46:37 EST 2010 Erik de Castro Lopo <erikd@…>
Fix #147 : Require that negative literals are enclosed in parentheses.

Also update tests.

Note: See TracTickets for help on using tickets.