=========================================
Type Class Instance Declarations
=========================================

instance Show Int where
instance Show Int where {}
instance Show Int
instance Show Int a where
instance Show Int a where {}
instance Show Int a
instance Show (Maybe a) where
instance Show (Maybe a) where {}
instance Show (Maybe a)
instance Show (a, b, c) where
instance Show (a, b, c) where {}
instance Show (a, b, c)
instance Show [a] where
instance Show [a] where {}
instance Show [a]
instance Show (a -> b) where
instance Show (a -> b) where {}
instance Show (a -> b)
instance Show Foo where
  bar (Foo Baz) (Foo Wix) = EQ
instance Show Foo where {
  bar (Foo Baz) (Foo Wix) = EQ
}
instance Show (,) where
instance Show (,) where {}
instance Show (,)
instance Show (Bar, Baz a b) where
instance Show (Bar, Baz a b) where {}
instance Show (Bar, Baz a b)
instance Show [(Bar, Baz a b)] where
instance Show [(Bar, Baz a b)] where {}
instance Show [(Bar, Baz a b)]
instance Show [Bar] where
instance Show [Bar] where {}
instance Show [Bar]
instance Show [Bar a b] where
instance Show [Bar a b] where {}
instance Show [Bar a b]
instance Show [Bar Baz b] where
instance Show [Bar Baz b] where {}
instance Show [Bar Baz b]

---

(module
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (type_constructor_identifier))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (type_constructor_identifier))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (type_constructor_identifier)))

  (type_class_instance_declaration
    (type_class_identifier)
    (instance (type_constructor_identifier) (type_variable_identifier))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (type_constructor_identifier) (type_variable_identifier))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (type_constructor_identifier) (type_variable_identifier)))

  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (parenthesized_type_pattern
        (type_constructor_identifier)
        (type_variable_identifier)))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (parenthesized_type_pattern (type_constructor_identifier) (type_variable_identifier)))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (parenthesized_type_pattern (type_constructor_identifier) (type_variable_identifier))))

  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (tuple_type
        (type (type_variable_identifier))
        (type (type_variable_identifier))
        (type (type_variable_identifier))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (tuple_type
        (type (type_variable_identifier))
        (type (type_variable_identifier))
        (type (type_variable_identifier))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (tuple_type
        (type (type_variable_identifier))
        (type (type_variable_identifier))
        (type (type_variable_identifier)))))

  (type_class_instance_declaration
    (type_class_identifier)
    (instance (list_type (type (type_variable_identifier))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (list_type (type (type_variable_identifier))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (list_type (type (type_variable_identifier)))))

  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (parenthesized_type_pattern
        (function_type
          (type (type_variable_identifier))
          (type (type_variable_identifier)))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (parenthesized_type_pattern
        (function_type
          (type (type_variable_identifier))
          (type (type_variable_identifier)))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (parenthesized_type_pattern
        (function_type
          (type (type_variable_identifier))
          (type (type_variable_identifier))))))

  (type_class_instance_declaration
    (type_class_identifier)
    (instance (type_constructor_identifier))
    (where
      (function_declaration
        (variable_identifier)
        (parenthesized_pattern
          (constructor_pattern (constructor_identifier) (constructor_identifier)))
        (parenthesized_pattern
          (constructor_pattern (constructor_identifier) (constructor_identifier)))
        (function_body (constructor_identifier)))))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (type_constructor_identifier))
    (where
      (function_declaration
        (variable_identifier)
        (parenthesized_pattern
          (constructor_pattern (constructor_identifier) (constructor_identifier)))
        (parenthesized_pattern
          (constructor_pattern (constructor_identifier) (constructor_identifier)))
        (function_body (constructor_identifier)))))

  (type_class_instance_declaration
    (type_class_identifier)
    (instance (tupling_constructor))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (tupling_constructor))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (tupling_constructor)))

  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (tuple_type
        (type (type_constructor_identifier))
        (type (type_constructor_identifier) (type_variable_identifier) (type_variable_identifier))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (tuple_type
        (type (type_constructor_identifier))
        (type (type_constructor_identifier) (type_variable_identifier) (type_variable_identifier))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (tuple_type
        (type (type_constructor_identifier))
        (type (type_constructor_identifier) (type_variable_identifier) (type_variable_identifier)))))

  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (list_type
        (type
          (tuple_type
            (type (type_constructor_identifier))
            (type (type_constructor_identifier) (type_variable_identifier) (type_variable_identifier))))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (list_type
        (type
          (tuple_type
            (type (type_constructor_identifier))
            (type (type_constructor_identifier) (type_variable_identifier) (type_variable_identifier))))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (list_type
        (type
          (tuple_type
            (type (type_constructor_identifier))
            (type (type_constructor_identifier) (type_variable_identifier) (type_variable_identifier)))))))

  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (list_type (type (type_constructor_identifier))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (list_type (type (type_constructor_identifier))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (list_type (type (type_constructor_identifier)))))

  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (list_type
        (type (type_constructor_identifier) (type_variable_identifier) (type_variable_identifier))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (list_type
        (type (type_constructor_identifier) (type_variable_identifier) (type_variable_identifier))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (list_type
        (type (type_constructor_identifier) (type_variable_identifier) (type_variable_identifier)))))

  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (list_type
        (type (type_constructor_identifier) (type_constructor_identifier) (type_variable_identifier))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (list_type
        (type (type_constructor_identifier) (type_constructor_identifier) (type_variable_identifier))))
    (where))
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (list_type
        (type (type_constructor_identifier) (type_constructor_identifier) (type_variable_identifier))))))

=========================================
Type Class Instance Declarations With Context
=========================================

instance Show a => Read Int where {}
instance Show a => Read (Maybe a) where {}
instance (Show a, Eq a) => Read (Maybe a) where {}
instance (Foo (Bar [Baz])) => Read (Bar) where {}
instance (Foo (Bar (Baz, Baz))) => Read (Bar) where {}

---

(module
  (type_class_instance_declaration
    (context
      (context_pattern
        (class (type_class_identifier) (type_variable_identifier))))
    (type_class_identifier)
    (instance (type_constructor_identifier))
    (where))
  (type_class_instance_declaration
    (context
      (context_pattern
        (class (type_class_identifier) (type_variable_identifier))))
    (type_class_identifier)
    (instance (parenthesized_type_pattern (type_constructor_identifier) (type_variable_identifier)))
    (where))
  (type_class_instance_declaration
    (context
      (context_pattern
        (class (type_class_identifier) (type_variable_identifier)))
      (context_pattern
        (class (type_class_identifier) (type_variable_identifier))))
    (type_class_identifier)
    (instance (parenthesized_type_pattern (type_constructor_identifier) (type_variable_identifier)))
    (where))
  (type_class_instance_declaration
    (context
      (context_pattern
        (class
          (type_class_identifier)
          (parenthesized_type_pattern
            (type_constructor_identifier)
            (list_type (type (type_constructor_identifier)))))))
    (type_class_identifier)
    (instance (parenthesized_type_pattern (type_constructor_identifier)))
    (where))
  (type_class_instance_declaration
    (context
      (context_pattern
        (class
          (type_class_identifier)
          (parenthesized_type_pattern
            (type_constructor_identifier)
            (tuple_type
              (type (type_constructor_identifier))
              (type (type_constructor_identifier)))))))
    (type_class_identifier)
    (instance (parenthesized_type_pattern (type_constructor_identifier)))
    (where)))

=========================================
Type Class Instance Declarations With Body
=========================================

instance Foo Bar where
  baz :: Num b => a -> b -> a
  baz' :: (Num a, Num b) => Maybe a -> Either String b -> Maybe (Either String a)

---

(module
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (type_constructor_identifier))
    (where
      (type_signature
        (variable_identifier)
        (annotation)
        (context (context_pattern (class (type_class_identifier) (type_variable_identifier))))
        (function_type
          (type (type_variable_identifier))
          (function_type
            (type (type_variable_identifier))
            (type (type_variable_identifier)))))
      (type_signature
        (variable_identifier)
        (annotation)
        (context
          (context_pattern (class (type_class_identifier) (type_variable_identifier)))
          (context_pattern (class (type_class_identifier) (type_variable_identifier))))
        (function_type
          (type
            (type_constructor_identifier)
            (type_variable_identifier))
          (function_type
            (type
              (type_constructor_identifier)
              (type_constructor_identifier)
              (type_variable_identifier))
            (type
              (type_constructor_identifier)
              (parenthesized_type_pattern
                (type_constructor_identifier)
                (type_constructor_identifier)
                (type_variable_identifier)))))))))

=========================================
Multi-param Type Class Instance Declarations
=========================================

instance Bar a b m => Baz a b m where {}

---

(module
  (type_class_instance_declaration
    (context
      (context_pattern
        (class
        (type_class_identifier)
        (type_variable_identifier)
        (type_variable_identifier)
        (type_variable_identifier))))
    (type_class_identifier)
    (instance
      (type_variable_identifier)
      (type_variable_identifier)
      (type_variable_identifier))
    (where)))

=========================================
Type Class Instance Declarations With Simple Contexts Including Promoted Constructors
=========================================

instance ( Foo (Bar a b '[]) c ) => Baz a b (Bix a b c) where

---

(module
  (type_class_instance_declaration
    (context
      (context_pattern
        (class
        (type_class_identifier)
        (parenthesized_type_pattern
          (type_constructor_identifier)
          (type_variable_identifier)
          (type_variable_identifier)
          (quoted_name (list_constructor)))
        (type_variable_identifier))))
    (type_class_identifier)
    (instance
      (type_variable_identifier)
      (type_variable_identifier)
      (parenthesized_type_pattern
        (type_constructor_identifier)
        (type_variable_identifier)
        (type_variable_identifier)
        (type_variable_identifier)))
    (where)))


=========================================
Type Class Instance Declarations With Equality Constraints
=========================================

instance (Bar baz ~ foo) => Wix baz where
  toWix = undefined
  Wix baz <> Wix baz' = Wix (baz <> baz')

---

(module
  (type_class_instance_declaration
    (context
      (context_pattern
        (equality_constraint
          (equality_lhs (class (type_class_identifier) (type_variable_identifier)))
          (equality_rhs (type_variable_identifier)))))
    (type_class_identifier)
    (instance (type_variable_identifier))
    (where
      (function_declaration
        (variable_identifier)
        (function_body (variable_identifier)))
      (function_declaration
        (constructor_pattern
          (constructor_identifier)
          (variable_identifier))
        (variable_operator (variable_symbol))
        (constructor_pattern
          (constructor_identifier)
          (variable_identifier))
        (function_body
          (function_application
            (constructor_identifier)
            (parenthesized_expression
              (infix_operator_application
                (variable_identifier)
                (variable_operator (variable_symbol))
                (variable_identifier)))))))))

=========================================
Type Class Instance Declarations With Constructor Operators
=========================================

instance Bar (f :+: g) where {}

instance (A :< b, B :< b) => Bar (A c) Foo where {}

---

(module
  (type_class_instance_declaration
    (type_class_identifier)
    (instance
      (parenthesized_type_pattern
        (infix_operator_pattern
          (type (type_variable_identifier))
          (constructor_operator (constructor_symbol))
          (type (type_variable_identifier)))))
    (where))
  (type_class_instance_declaration
    (context
      (context_pattern
        (type_constructor_identifier)
        (constructor_operator (constructor_symbol))
        (type_variable_identifier))
      (context_pattern
        (type_constructor_identifier)
        (constructor_operator (constructor_symbol))
        (type_variable_identifier)))
      (type_class_identifier)
      (instance
        (parenthesized_type_pattern
          (type_constructor_identifier)
          (type_variable_identifier))
        (type_constructor_identifier))
      (where)))

=========================================
Type Class Instance Declarations Without Where
=========================================

instance Bar Baz

---

(module
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (type_constructor_identifier))))

=========================================
Type Class Instance Declarations Without Labeled Patter
=========================================

instance Foo Bar where
  foo D.F{..} = foo

---

(module
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (type_constructor_identifier))
    (where
      (function_declaration
        (variable_identifier)
        (labeled_pattern (qualified_constructor_identifier (module_identifier) (constructor_identifier)) (record_wild_cards))
        (function_body (variable_identifier))))))

=========================================
Type Class Instance Declarations With Repeating Parenthesized Patterns
=========================================

instance Show Foo where
  bar (Foo Baz) (Foo Baz) = EQ

---

(module
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (type_constructor_identifier))
    (where
      (function_declaration
        (variable_identifier)
        (parenthesized_pattern
          (constructor_pattern (constructor_identifier) (constructor_identifier)))
        (parenthesized_pattern
          (constructor_pattern (constructor_identifier) (constructor_identifier)))
        (function_body (constructor_identifier))))))

=========================================
Type Class Instance Declarations With Scoped Type Variables
=========================================

instance forall location a b. (Show a, Monad b) => MonadError (Value a) m where
  unit = pure . Unit

---

(module
  (type_class_instance_declaration
    (scoped_type_variables
      (type_variable_identifier)
      (type_variable_identifier)
      (type_variable_identifier)
      (dot))
      (context
        (context_pattern (class (type_class_identifier) (type_variable_identifier)))
        (context_pattern (class (type_class_identifier) (type_variable_identifier))))
    (type_class_identifier)
    (instance
      (parenthesized_type_pattern (type_constructor_identifier) (type_variable_identifier))
      (type_variable_identifier))
    (where
      (function_declaration
        (variable_identifier)
        (function_body
          (infix_operator_application
            (variable_identifier)
            (variable_operator (variable_symbol))
            (constructor_identifier)))))))

=========================================
Non-aligned Comment Between Instance Declarations
=========================================

instance Show A where b = c
  -- a
instance Show A where b = c

---

(module
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (type_constructor_identifier))
    (where
      (function_declaration
        (variable_identifier)
        (function_body (variable_identifier)))))
  (comment)
  (type_class_instance_declaration
    (type_class_identifier)
    (instance (type_constructor_identifier))
    (where
      (function_declaration
        (variable_identifier)
        (function_body (variable_identifier))))))
