Skip to content

[Feature] Attach attributes inside imported algebraic types #40

@b0o

Description

@b0o

It seems a large use case for import is, as stated in the readme, for use with deriving to derive functions for types that you do not own.

It is commonly necessary to place attributes within a definition of an algebraic type to specify the desired behavior of a deriving plugin. However, this does not seem to be currently possible with import.

For example, I have a use case (see #39) where I need to derive sexp conversion functions for a type I do not own:

Library code:

(* I3ipc.Event.workspace_event_info *)
type workspace_event_info = {
  change: workspace_change;
  current: Reply.node option;
  old: Reply.node option;
}

I can accomplish this:

type workspace_event_info = [%import: I3ipc.Event.workspace_event_info] [@@deriving sexp]

However, I would really like to be able to attach [@default None] to the current and old option types:

type workspace_event_info = {
  change: workspace_change;
  current: Reply.node option [@default None];
  old: Reply.node option [@default None];
}

It would be nice if I could use the existing with syntax to accomplish this. Perhaps it would look something like this (I am not very familiar with ppx semantics):

type workspace_event_info = [%import: I3ipc.Event.workspace_event_info 
    [@with workspace_event_info.current := I3ipc.Event.workspace_event_info.current [@default None];
           workspace_event_info.old := I3ipc.Event.workspace_event_info.old [@default None]]] 
[@@deriving sexp]

Currently, my best idea of how to accomplish this is to simply duplicate the type definitions that I want to modify in this way, but I feel that this would be a good feature to make import more useful.

I would be happy to help implement such a feature with some guidance and feedback.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions