amulet icon indicating copy to clipboard operation
amulet copied to clipboard

Weird error when trying to create custom exception

Open Lupus opened this issue 5 years ago • 2 comments

I'm following code in 'exception.ml' and try to create my own exception, but run into an error. This is relevant part of my source file:

open import "prelude.ml"

type decode_error = Decode_error of string
deriving instance typeable decode_error

instance Exception.exception decode_error begin
  let describe_exception (Decode_error x) = "Decode error: " ^ x
end

Amc complains:

error (E1001)
  Variable not in scope: `describe_exception`

  Arising from use of the binding
    │ 
126 │   let describe_exception (Decode_error x) = "Decode error: " ^ x
    │       ^^^^^^^^^^^^^^^^^^

The following message has a detailed explanation: 1001.
Try 'amc explain 1001' to see it.

I'm not sure what's exactly wrong here.

Lupus avatar Nov 28 '19 13:11 Lupus

Instances should bring their methods into scope within the instance body, but apparently we overlooked that. Sorry!

A temporary workaround would be placing open Exception somewhere before your definition.

SquidDev avatar Nov 28 '19 13:11 SquidDev

Yeah, I already worked around exactly the way you suggest :)

Lupus avatar Nov 28 '19 13:11 Lupus