Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate identity functions for Unit values #20

Open
winitzki opened this issue Feb 6, 2018 · 1 comment
Open

Generate identity functions for Unit values #20

winitzki opened this issue Feb 6, 2018 · 1 comment

Comments

@winitzki
Copy link
Collaborator

winitzki commented Feb 6, 2018

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.

@winitzki
Copy link
Collaborator Author

This simplification seems to be problematic; it prevents correct typing of case objects for the example Option[Option[A]] => Option[Option[A]].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant