Skip to content

Generate identity functions for Unit values #20

@winitzki

Description

@winitzki

When generating a function such as Option[A] => Option[A], the preferred implementation would be x => x. Sometimes code such as this is generated:

Warning:(141, 89) type (A  Option[B]{None.type + Some[B]})  (B  Option[C]{None.type + Some[C]})  A  Option[C]{None.type + Some[C]} has 2 implementations (laws need checking?):
 a  b  c  a c match { d  (None() + 0); e  b e.value } [score: (0,0.5,0.0,0,0)];
 a  b  c  (None() + 0) [score: (3,0.0,0.0,0,0)].
    def kleisliOptCompose[A, B, C](f: A  Option[B], g: B  Option[C]): A  Option[C] = implement

It is better to generate code such as x match { d => d }; ... instead of x match { d => None() + 0 }; ... when d is itself already None(). This code would have a lower information loss score.

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