amulet
amulet copied to clipboard
Weird error when trying to create custom exception
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.
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.
Yeah, I already worked around exactly the way you suggest :)