Can exception types be common?

I tried the following which does not work.

exception MyError<'a> of 'a
exception 'a MyError of 'a

Do I need to use a long form:

type MyError<'a>(value) =
  inherit System.Exception()
  member this.Value : 'a = value
+3
source share
1 answer

According to the specification, you should use a long form. I did not find an explanation of why this is the case, but the grammar descriptions for the exceptions look like this (and maybe also hints why the behavior is the way you described):

exception-defn: = attributes optexception data of type union-type-case

union-type-case-data: =
                                            (case with zero union)
      ident of type * ... * type   (n-ary union case)
      Identifier: uncurried-sig       (n-ary union case)

, , , . , ...

exception MyExn of int

... , System.Exception ( ). , :

type System.Exception = 
  | ...
  | MyExn of int
+6

All Articles