Comments (4)
We should use idris-testing or, better yet, Specdris (#43).
from idris.
Edit: I should've mentioned this right away. Thanks for starting this discussion!
That's not the real issue here though. Let me try to elaborate.
Altering the bespoke assertEq
to be more specific is not the correct approach here.
assertEq : Eq a => String -> (given : a) -> (expected : a) -> IO ()
It specifies that assertEq
means to compare two values of type a
, under the constraint that a
has an implementation of Eq
. The implementation you linked does not satisfy that invariant, because the type checker cannot be sure that b
has an implementation of Eq
. The solution to your generic implementation then is to add the constraint:
accumulate : Eq b => (a -> b) -> List a -> List b
What all that said, the tests expect the solution to have the following signature, as per the stub.
accumulate : (Int -> Int) -> List Int -> List Int
Notably, the following test fails to type check when you alter the signature of accumulate
, as in the linked solution.
testDecrementFunctionAddsOneToAllInput : IO ()
testDecrementFunctionAddsOneToAllInput = assertEq "decrement function subtracts 1 from input" (accumulate (\x => x - 1) [1,2,3]) [0,1,2]
When checking right hand side of testDecrementFunctionAddsOneToAllInput with expected type
IO ()
When checking argument smaller to function Prelude.Nat.-:
Can't find a value of type
LTE 1 x
So if we want to support a more generic accumulate
(I can see arguments both ways), the necessary changes are more broad in scope than just assertEq
.
Hot take re: making accumulate
generic
- Pros: more traditional FP, good learning exercise, intro to type constraints
- Cons: could be too much too soon (intro to type constraints), need to change most/all of test (not a big deal, obviously)
I've had a long day/week. Does this blathering make any sense?
from idris.
It does make sense.
I still believe generalising the signature should be accepted by tests, even if the stub stays the same.
The type errors you've cited stem from the compiler either not specialising b
(the empty list case), or selecting a wrong type for numbers (the LTE 1 x
case). Both cases could be solved by specifying the type of lists used in tests. That's what my proposition really does, by specialising the assertEq
helper.
from idris.
Ok, Iād be happy to review/merge a PR.
from idris.
Related Issues (20)
- Build representer
- Check docs are up to date
- Fix CI
- Launch tracking
- Move from Travis to GitHub Actions HOT 3
- Add nucleotide-count exercise
- Add kindergarten-garden exercise
- Add list-ops exercise
- Add pascals-triangle exercise
- exercises/practice/grains/src/Grains.idr
- Pass linting checks HOT 1
- Build Test Runner
- Build Representer and Analyzer HOT 1
- Update status of track
- Update status of Concept Exercises HOT 1
- Launch Tracker š“
- Add language blurb
- š¤ Sync error for commit a955c6
- Extract track-specific help instructions from `config/exercise_readme.go.tmpl`
- Extract track-specific test instructions from `config/exercise_readme.go.tmpl`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from idris.