Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/justinwoo/purescript-expect-inferred
Library for checking inferred types of values for testing
https://github.com/justinwoo/purescript-expect-inferred
purescript
Last synced: 15 days ago
JSON representation
Library for checking inferred types of values for testing
- Host: GitHub
- URL: https://github.com/justinwoo/purescript-expect-inferred
- Owner: justinwoo
- License: mit
- Created: 2018-08-10T12:23:51.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-15T12:57:38.000Z (about 3 years ago)
- Last Synced: 2024-12-07T04:03:52.718Z (about 1 month ago)
- Topics: purescript
- Language: PureScript
- Homepage:
- Size: 5.86 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# purescript-expect-inferred
[![Build Status](https://travis-ci.org/justinwoo/purescript-expect-inferred.svg?branch=master)](https://travis-ci.org/justinwoo/purescript-expect-inferred)
Library for when you want to expect that something is inferred correctly. This library is not commonly useful.
## How this works
```purs
class ExpectInferred expected actual
```No fundeps, so both have to be determined to match anything, which means that in PureScript, you have to let-bind your intermediate actual results.
```purs
expectInferred
:: forall expected actual
. ExpectInferred expected actual
=> Proxy expected
-> actual
-> Unit
expectInferred _ _ = unit
```## Usage
Given some class and some of its methods:
```purs
class SimpleClass a b | a -> b where
simpleMethod :: Proxy a -> binstance simpleInstance1 :: SimpleClass Int String where
simpleMethod _ = "hello"instance simpleInstance2 :: SimpleClass String Unit where
simpleMethod _ = unit
```We can see usage as expected:
```purs
test1 :: Unit
test1 =
let
expectedP = Proxy :: Proxy String
simpleValue = simpleMethod (Proxy :: Proxy Int)
in
expectInferred expectedP simpleValue
```Then, when we put the wrong thing in:
```purs
test2 :: Unit
test2 =
let
-- this will error correctly:
expectedP = Proxy :: Proxy String
-- A custom type error occurred while solving type class constraints:
--
-- The expected (first) and actual (second) types did not match:
-- String
-- Unit
--
-- while applying a function expectInferred
-- of type ExpectInferred t0 t1 => Proxy t0 -> t1 -> Unit
-- to argument expectedP
-- while inferring the type of expectInferred expectedP
-- in value declaration test2simpleValue = simpleMethod (Proxy :: Proxy String)
in
expectInferred expectedP simpleValue
```