From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by c5ff346549e7 (Postfix) with ESMTPS id 28E9C5D5 for ; Sun, 24 Jan 2021 14:34:51 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.79,371,1602540000"; d="scan'208";a="488739661" Received: from prod-listesu18.inria.fr (HELO sympa.inria.fr) ([128.93.162.160]) by mail2-relais-roc.national.inria.fr with ESMTP; 24 Jan 2021 15:34:48 +0100 Received: by sympa.inria.fr (Postfix, from userid 20132) id BAACCE0131; Sun, 24 Jan 2021 15:34:46 +0100 (CET) Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 522F0E00A6 for ; Sun, 24 Jan 2021 15:34:41 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=oliver@first.in-berlin.de; spf=None smtp.mailfrom=oliver@first.in-berlin.de; spf=None smtp.helo=postmaster@einhorn-mail-out.in-berlin.de IronPort-PHdr: =?us-ascii?q?9a23=3AYrEUnx36RKEBgN+IsmDT+DRfVm0co7zxezQtwd8Z?= =?us-ascii?q?seMVKPad9pjvdHbS+e9qxAeQG9mCurQe0qGK6eigATVGvc/e9ihaMdRlbFwssY?= =?us-ascii?q?0uhQsuAcqIWwXQDcXBSGgEJvlET0Jv5HqhMEJYS47UblzWpWCuv3ZJQk2sfQV6?= =?us-ascii?q?Kf7oFYHMks+5y/69+4HJYwVPmTGxfa5+IA+5oAnMssQam5VuJrs+xhbGvHdDZu?= =?us-ascii?q?BayX91KV6JkBvw+8W98IR//yhMvv4q6tJNX7j9c6kkV7JTES4oM3oy5M3ltBnD?= =?us-ascii?q?SRWA634BWWgIkRRGHhbI4gjiUpj+riX1uOx92DKHPcLtVrA7RS6i76ZwRxD2ji?= =?us-ascii?q?oMKiM0/3vWisx0i6JbvQ6hqhliyIPafI2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h?= =?us-ascii?q?WNjzRGhpFottke9LWF50HpCZtj6GxzCjWedHmb2RH4By86SZ1XXrI8d7jXrLhv?= =?us-ascii?q?F40gsWB/BXPGjjvZZRsgjeA4mSyheUlqCqcr4amSvE9WPGyneS+kBeFQR9S6HE?= =?us-ascii?q?WzYTaxmO9IWr1gb5V7arTI8fHE5EwM+GJLFNb4ex31tHXuz/ftXYJmi8gWOxA1?= =?us-ascii?q?CEy+HUYQ=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CvAQDwhA1glxVQxdliHQEBAQEJARIBB?= =?us-ascii?q?QUBQIFPAoN2ATIvhECJBIY9ghcDmkaBewsBAwELAQEvBAEBhEoCgXgCHQYGNgQ?= =?us-ascii?q?NAhABAQUBAQECAQMDBAETAQEBAQEBAQEJFgaGHYI4KQGDEgEEASNWEAsaAiYCA?= =?us-ascii?q?lcGE4MmglYDDiSzRYEyhVmCRCJNgUSBDiqFZxI9hwgmG4IAgRE2gjUuPodXgmA?= =?us-ascii?q?Egj6BAgMQW0RQkHk1qCqBb4ESgR2aQw8igSORcY9ksR4ThEMCCgcWgXACSIEtM?= =?us-ascii?q?xoIHBQ7gmlQGQ2OO44wQAMwNwIGCgEBAwmMFQEB?= X-IPAS-Result: =?us-ascii?q?A0CvAQDwhA1glxVQxdliHQEBAQEJARIBBQUBQIFPAoN2ATI?= =?us-ascii?q?vhECJBIY9ghcDmkaBewsBAwELAQEvBAEBhEoCgXgCHQYGNgQNAhABAQUBAQECA?= =?us-ascii?q?QMDBAETAQEBAQEBAQEJFgaGHYI4KQGDEgEEASNWEAsaAiYCAlcGE4MmglYDDiS?= =?us-ascii?q?zRYEyhVmCRCJNgUSBDiqFZxI9hwgmG4IAgRE2gjUuPodXgmAEgj6BAgMQW0RQk?= =?us-ascii?q?Hk1qCqBb4ESgR2aQw8igSORcY9ksR4ThEMCCgcWgXACSIEtMxoIHBQ7gmlQGQ2?= =?us-ascii?q?OO44wQAMwNwIGCgEBAwmMFQEB?= X-IronPort-AV: E=Sophos;i="5.79,371,1602540000"; d="scan'208";a="488739609" X-MGA-submission: =?us-ascii?q?MDFCxPc/orKdqibEz+Opy4KWJ2LhWxd3mnpnvk?= =?us-ascii?q?UrftEy37ilnCRoCQ5XzLUxwJL6AWYBTRq3k9s4TfxRKMOcIuLQXSMEtu?= =?us-ascii?q?7qf+qTGS7QQ6BoTj6sQMqKV12HHPl+6K3apZR/XJLoNX1DBZ9GLxD7We?= =?us-ascii?q?mSluCl79wI+0Py0xnZ26hmAQ=3D=3D?= Received: from einhorn-mail-out.in-berlin.de ([217.197.80.21]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jan 2021 15:34:24 +0100 X-Envelope-From: oliver@first.in-berlin.de Received: from authenticated.user (localhost [127.0.0.1]) by einhorn.in-berlin.de with ESMTPSA id 10OEYMLu009466 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 24 Jan 2021 15:34:22 +0100 Date: Sun, 24 Jan 2021 15:34:20 +0100 From: Oliver Bandel To: Markus Elfring Cc: caml-list@inria.fr Message-ID: <20210124143420.443qexv5dvgtqpbm@first.in-berlin.de> References: <41485ac7-50cf-08fe-4206-b9f863c4d2f5@web.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <41485ac7-50cf-08fe-4206-b9f863c4d2f5@web.de> Subject: Re: [Caml-list] Detecting missed checks for error indications in ML code Reply-To: Oliver Bandel X-Loop: caml-list@inria.fr X-Sequence: 18378 Errors-To: caml-list-owner@inria.fr Precedence: list Precedence: bulk Sender: caml-list-request@inria.fr X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: Hi, Quoting Markus Elfring (snt: 2021-01-24 12:42 +0100 CET) (rcv: 2021-01-24 12:42 +0100 CET): > Hello, > > OCaml belongs also to the category of functional programming languages. > Thus the last expression in a function usually becomes the result of > the data processing which was specified in a ML source file. > This would usually happen also if the return value from a function call > indicates an error code (when a function implementation does not throw an exception > according to an error situation). [...] It is very common in other languages to somehow encode "errors" or "missing values" via the result itself, by selecting a more or less "obvius" (at the time of writing the function) value as representing an error or missing value. Let's call it the socilogogists approach, because I often saw sociologists encode their data with natural numbers (starting at 1), for say 7 or so categories, and the "no data available" was encoded as 99. (R offers NA and NaN, but sociologists tend(ed) to use SPSS or Excel and the 99 as exceptional value was common for decades; I think it's still handled this way today.) Similarly in Perl or other languages, often the empty string is used (undef would be better; like NULL in C, which makes sense, just don't dereference it; in python you have None; ...) for indicating a certain return value, which is used like the sociologist's 99. But OCaml isn't just only a functional language. It's also a typed language. And the type system can help you at this point. You can use the option-type for indicating missing data. So, None and Some "" would be different. The None indicates that there is no data available, while the Some "" says: hey, we have data, but it's the empty string. In that way, the empty string is not indicating a problem anymore. And that means, that the problem you have in mind disappears! (And if getting the empty string from the source of your data is indeed only possible in case of an error, return None instead of Some "" and you have made the conversion to a type safe return value. From the outside then there will be no Some "" in the set of possibly returned values.) > > I got the impression that corresponding error checks can occasionally be missing. > How do you think about to detect such cases by advanced source code analysis? No need to thest these kind of problems, as long as you use the type system to help you as mentioned above. Of course you can stick to the sociologists way of coding your data and return values also in OCaml. But if you use the possibilities the OCaml's type system offers, all that clutter with problematic values is excluded from the beginning. No need for extra testing. Just look at the signature of your functions. Since a while OCaml also offers a result-type, which you can use. It might be better than the option type in more general cases. And if predefined types don't offer what you are looking for, just define your own type. Ciao, Oliver