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

Equivalent of fantasy-laws? #58

Open
NodeGuy opened this issue Dec 30, 2019 · 2 comments
Open

Equivalent of fantasy-laws? #58

NodeGuy opened this issue Dec 30, 2019 · 2 comments

Comments

@NodeGuy
Copy link

NodeGuy commented Dec 30, 2019

Is there a way to programmatically test types for compliance with the various laws, similar to using fantasy-laws for Fantasy Land?

@baetheus
Copy link

I've written a few assert law functions for various type classes here. They are not complete, but I'll likely expand on them as I build that library. If you want to steal them for your own devices feel free!

Be aware that I ran into some issues when comparing the results of the tests for ADTs like Reader and Task, since their type signatures (in my implementation) are:

export type Reader<R, A> = (r: R) => A;
export type Task<A> = () => Promise<A>;

Deno's assertEquals is not quite smart enough to compare functions (as far as I know this is a pretty hard problem). In these cases I had to settle for testing the output of executing the types, as seen here for reader and here for task.

Hope this helps you in some way.

@baetheus
Copy link

baetheus commented Oct 10, 2020

I spent today expanding my test suite to be more flexible. You can find those tests with fully compliant types in the latest release of hkts here. Not that I've also "shimmed" an assertFunction so I don't have to treat task, reader, io, etc any differently from other monads/adts. It's a little hacky though.

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