Implementing the Grains exercise

Hello,

I am looking to implement the Grains exercise in OCaml.

There is a stumbling block here in that OCaml does not have a way to implement unsigned 64-bit integers, even in the Base module. Importing a library to deal with the above would be a terrible idea.

Would returning a string representation of the integer be an acceptable solution? If so then the student will also have to write a helper function for this exercise.

This may also require the use of YoJson.Safe rather than .Basic, to allow the safe parsing of the numbers in the test cases.

Given the go ahead, I will look at implementing this in the week.

In PHP we also use strings as the expected return type for the same reason. I have no idea of the difficulty of that helper function in OCaml, but in PHP it definitely raises the difficulty from easy to medium.

1 Like

I think that would be the case here too!

vimscript does the same.

2 Likes

An instructions append highlighting why a string approach is needed in OCaml would be useful. Students will then understand some of the limitations of the language and how to work around them. Here is an example instructions append from Vim script.

3 Likes