View Source cure_derive (cure v0.7.0)
Summary
Functions
Checks if a typeclass can be automatically derived for a type.
Derives an Eq instance for a record type.
Automatically derives a typeclass instance for a given type.
Derives an Ord instance for a record type.
Derives a Show instance for a record type.
Functions
Checks if a typeclass can be automatically derived for a type.
Arguments
TypeclassName- Name of the typeclassForType- Type to check
Returns
true- Can be derivedfalse- Cannot be derived
-spec derive_eq(term(), [term()], term()) -> {ok, #instance_def{typeclass :: term(), type_args :: term(), constraints :: term(), methods :: term(), location :: term()}} | {error, term()}.
Derives an Eq instance for a record type.
Generates equality check that compares all fields structurally.
-spec derive_instance(atom(), term(), [term()], term()) -> {ok, #instance_def{typeclass :: term(), type_args :: term(), constraints :: term(), methods :: term(), location :: term()}} | {error, term()}.
Automatically derives a typeclass instance for a given type.
Arguments
TypeclassName- Name of the typeclass to derive (e.g., 'Show', 'Eq')ForType- Type expression to derive instance forConstraints- Required constraints for the instanceTypeEnv- Type environment with type definitions
Returns
{ok, InstanceDef}- Generated instance definition{error, Reason}- Cannot derive instance
Example
{ok, ShowInstance} = cure_derive:derive_instance(
'Show',
#record_type{name = 'Person'},
[],
TypeEnv
).
-spec derive_ord(term(), [term()], term()) -> {ok, #instance_def{typeclass :: term(), type_args :: term(), constraints :: term(), methods :: term(), location :: term()}} | {error, term()}.
Derives an Ord instance for a record type.
Generates lexicographic ordering based on field order. Requires Eq instance (superclass).
-spec derive_show(term(), [term()], term()) -> {ok, #instance_def{typeclass :: term(), type_args :: term(), constraints :: term(), methods :: term(), location :: term()}} | {error, term()}.
Derives a Show instance for a record type.
Generates a show method that displays the record as: RecordName { field1: value1, field2: value2 }