caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Bahman Movaqar <bahman@bahmanm.com>
To: caml-list@inria.fr
Subject: [Caml-list] On variants, integers and testing
Date: Fri, 16 Mar 2018 12:12:56 +0100	[thread overview]
Message-ID: <CACOw_MrR5M66=CB8Z=f7B+xiv5r8U87P3kE=p_8kyu8OCKCrjw@mail.gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2018-03-16 11:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-16 11:12 Bahman Movaqar [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACOw_MrR5M66=CB8Z=f7B+xiv5r8U87P3kE=p_8kyu8OCKCrjw@mail.gmail.com' \
    --to=bahman@bahmanm.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).