caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] On variants, integers and testing
@ 2018-03-16 11:12 Bahman Movaqar
  2018-03-19 10:41 ` Cedric Cellier
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Bahman Movaqar @ 2018-03-16 11:12 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1977 bytes --]

I'm new to OCaml so please bear with me.

As a practice, I implemented the solution to problem 54 of Project Euler
(poker hands).

* The original problem https://projecteuler.net/problem=54
* The solution:
  - https://github.com/bahmanm/euler-ml/blob/master/src/p54.mli
  - https://github.com/bahmanm/euler-ml/blob/master/src/p54.ml
  - https://github.com/bahmanm/euler-ml/blob/master/test/test_p54.ml

I have 2 questions and 1 favour to ask :-)

Q1
==
To limit the values possible for a card's actual value, I defined `Value`
module (line 6) which basically maps a variant to integer values.
Is this the idiomatic approach? Is there something like Java's enum or
Pascal's subranges that I could use[1]?

Q2
==
Suppose that I wrote this piece of code as a library to be used by others
as well. In such a case, practically the only function that the users are
interested in is `solve`, as defined in the .mli file.
This is good: keeps my library clean, the usage straight-forward and
doesn't confuse the users.

However, when it comes to testing, things are not that simple. Now that I
have exported only 1 function in the .mli, I can only test that 1 function.
Is this the proper way[2]?

Favour
======
I'd be really grateful if somebody would spend some of her/his precious
time and took a look at the code that I wrote, just to give me broad
pointers how this can be improved or be more idiomatic.

[1] I noticed Batteries bounded types, but when I used it, it felt like an
overkill for my purpose.
[2] I know this is a rather general question and the same question can be
applied to any other language. However some languages, such as D, let you
write unit tests next to the main code - or many OO languages have the
visibility modifier which can help.

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

[-- Attachment #2: Type: text/html, Size: 4725 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-03-21 14:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-16 11:12 [Caml-list] On variants, integers and testing Bahman Movaqar
2018-03-19 10:41 ` Cedric Cellier
2018-03-19 10:44   ` Cedric Cellier
2018-03-19 13:27 ` Yawar Amin
2018-03-19 13:49   ` Yawar Amin
2018-03-19 21:24 ` SP
2018-03-21 14:36   ` Lukasz Stafiniak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).