#Stuck on the Difference of Squares problem in OCaml

19 messages · Page 1 of 1 (latest)

gritty shoal
#

This is what I have
let sum_square_difference n =
let sum_of_squares = List.fold_left (fun acc x -> acc + x * x) 0 (List.init n (fun x -> x + 1)) in
let square_of_sum = let sum = List.fold_left (+) 0 (List.init n (fun x -> x + 1)) in sum * sum in
square_of_sum - sum_of_squares
;;

I get this error:
We received the following error when we ran your code:

File "difference_of_squares.ml", line 1:
Error: The implementation difference_of_squares.ml
does not match the interface .test.eobjs/byte/difference_of_squares.cmi:
The value square_of_sum' is required but not provided File "difference_of_squares.mli", line 2, characters 0-30: Expected declaration The value sum_of_squares' is required but not provided
File "difference_of_squares.mli", line 5, characters 0-31:
Expected declaration
The value `difference_of_squares' is required but not provided
File "difference_of_squares.mli", line 8, characters 0-38:
Expected declaration
make: *** [Makefile:4: test] Error 1

https://exercism.org/tracks/ocaml/exercises/difference-of-squares

Exercism

Can you solve Difference of Squares in OCaml? Improve your OCaml skills with support from our world-class team of mentors.

haughty kelp
#

The value `difference_of_squares' is required but not provided
The value sum_of_squares' is required but not provided
Do you define those values at the top level?

gritty shoal
#

top level?

gritty shoal
#

Ok I figure it out, why is Exercism testing intermediate functions? That severely constrains how one can write the solution? Shouldn't it just test that overall function is correct?

haughty kelp
#

It's not an intermediate function. It's explicitly part of what you need to write for this exercise.

tawny trailBOT
#

If everything is resolved, we ask that people react to the top/original post with a :white_check_mark: (:white_check_mark:). This indicates to others that this issue has been resolved and locks the thread.
If all the tests pass and you want to further improve your solution, we encourage you to use the "Request a Code Review" feature on the website!

gritty shoal
#

The task is to "Find the difference between the square of the sum and the sum of the squares of the first N natural numbers." it shouldn't need to check that you are finding the squares of sums and sums of squares corrrectly, just that you are finding the differences correctly, hence "intermediate functions"

haughty kelp
#

The requirements are embedded in the unit test. The prose is the overview, not the specs.

#

Exercise practice exercises are explicitly test driven

gritty shoal
#

Yes, and that's dumb

haughty kelp
#

Taking a test driven development approach?

#

You don't have to like it, but it's what Exercism is built around. If you don't like TDD, then Exercism may not be the best fit for you.

gritty shoal
#

Test driven development is for developing software. These are exercises not software so a test driven approach is antithetical to the goal of the site

haughty kelp
#

These exercises are here to help you practice writing software.

#

If it doesn't work for you, that's entirely fine! There's plenty of other sites out there and another one might be a better match for what you're looking for.

gritty shoal
#

They're not though, theyre to help us learn how to program generally or with a specific language. Best practices for programing "software" that will be used by the public and maintained/updated by others should properly be outside the scope of a Exercism and other such sites. Playing obtuse isn't a good look bro

haughty kelp
#

"how to program" and "writing software" is the same thing.

Test driven development isn't specifically for 'programing "software" that will be used by the public and maintained/updated by others'. It's a good practice for any software development. You only pick up those skills by practicing them!

#

Exercism is here to help people learn to write good code, and good coding skills. For writing software. All types of software.

#

What is and isn't in scope is set by Exercism. If Exercism decides TDD is in scope, then it's in scope.