From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id A95668239C for ; Wed, 31 Jan 2018 22:35:37 +0100 (CET) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=yawar.amin@gmail.com; spf=Pass smtp.mailfrom=yawar.amin@gmail.com; spf=None smtp.helo=postmaster@mail-it0-f46.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of yawar.amin@gmail.com) identity=pra; client-ip=209.85.214.46; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yawar.amin@gmail.com"; x-sender="yawar.amin@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of yawar.amin@gmail.com designates 209.85.214.46 as permitted sender) identity=mailfrom; client-ip=209.85.214.46; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yawar.amin@gmail.com"; x-sender="yawar.amin@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-it0-f46.google.com) identity=helo; client-ip=209.85.214.46; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yawar.amin@gmail.com"; x-sender="postmaster@mail-it0-f46.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AvDKrHRDlYa1vlRK0FQzfUyQJP3N1i/DPJgcQr6Af?= =?us-ascii?q?oPdwSPv+o8bcNUDSrc9gkEXOFd2Cra4c0qyO6+jJYi8p2d65qncMcZhBBVcuqP?= =?us-ascii?q?49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6?= =?us-ascii?q?JvjvGo7Vks+7y/2+94fcbglUmTaxe69+IAmrpgjNq8cahpdvJLwswRXTuHtIfO?= =?us-ascii?q?pWxWJsJV2Nmhv3+9m98p1+/SlOovwt78FPX7n0cKQ+VrxYES8pM3sp683xtBnM?= =?us-ascii?q?VhWA630BWWgLiBVIAgzF7BbnXpfttybxq+Rw1DWGMcDwULs5Qiqp4bt1RxD0iS?= =?us-ascii?q?cHLz85/3/Risxsl6JQvRatqwViz4LIfI2ZMfxzdb7fc9wHX2pMRsReVyJBDI2y?= =?us-ascii?q?bIUBEvQPMvpDoobnu1cDtwGzCRWwCO7tzDJDm3/43bc90+QkCQzJ3hYvHtwUv3?= =?us-ascii?q?TOsd74KKISUeGzzKLVyjjCb+lZ2Dnn54jSaBwuu/SMXbN2ccfKxkkvEhnKjlSU?= =?us-ascii?q?qYD/IzyV0eENvnGd4uF9Vuyvk3Yqpx9trjWr3MshiYnEipgLxlzZ+ih12ok4KN?= =?us-ascii?q?y+RUVme9CrCoFQuDufN4ZuQsMtXWVouCEix70Do5G7fSwKxI0mxx7Dd/CLaoaI?= =?us-ascii?q?7x3iWeqLLjd4g3VleL27hxms60Sv1ur8Vsys3FZLqCpKjMXMu2gT2xDP7sWLUP?= =?us-ascii?q?hw80e71TqRygze5ftILE81mKbDLp4u2L8wlp4dsUTZGS/2nV37ja+MeUQq4Oeo?= =?us-ascii?q?8f7rba/jpp+dMY95kQ7+MqE0lcy+BeQ0KBQBX2+e+eikzr3s4VX5QKlWjv0xiq?= =?us-ascii?q?TWrIrVJcEfpqKgBw9V050j6wqkAje90NUYmGEHI0hfdBKGiYjpIVDOL+riAfex?= =?us-ascii?q?mVT/2AtsktTBJLDnEJKFFn/GkbPgNeJ57FRRzhg0i8hY4pNQC+FcCP32U0718t?= =?us-ascii?q?ffC0lqHRazxrPWAcp0zMs3XGOJSvuIObzbqxmB4+MpC+aJbY4R/j36Lq52tLbV?= =?us-ascii?q?kXYllApFLuGS1pwNZSX9R6w+ehTLUT/Xmt4EVFwykE87Re3uhkeFVGcKNXm3Vq?= =?us-ascii?q?M4oDo8DdD/VNuRdsWWmLWEmRyDMNhOfGkfUwKDFH7pc8OPXPJeMHvPcP8kqSQN?= =?us-ascii?q?UP2ac6Fk1Ryqs1Wnmb9uL+6R+zFA8Jy/ip564OrckRx0/jtxXZyQ?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0BpBAB1NXJahi7WVdFdHAEBAQQBAQoBA?= =?us-ascii?q?YNpAYEzFRMKg1aBOZcXgV4FH4QAjXKHawqFOwKCSAcZBwQ0FAEBAQEBAQEBAQE?= =?us-ascii?q?BEgEBAQgLCwgoL4I4JAGCRwEEASMEGQEbHQEDAQsGBQs3AgIhAQERAQUBHAYTC?= =?us-ascii?q?IoUAQMNCJs4QIwUgW0YBQEcgwsFg2IKGScNWYJLAQEBAQEBBAEBAQEBGwIGEoR?= =?us-ascii?q?JghWBV4RgNoJrRASFBoJlBYgBglILiHpgjyg+gkqNR1WFBpQtizCCfoknFAUgg?= =?us-ascii?q?Rc2gXIzGiNSMoF4gkYfgjAjN4woAQEB?= X-IPAS-Result: =?us-ascii?q?A0BpBAB1NXJahi7WVdFdHAEBAQQBAQoBAYNpAYEzFRMKg1a?= =?us-ascii?q?BOZcXgV4FH4QAjXKHawqFOwKCSAcZBwQ0FAEBAQEBAQEBAQEBEgEBAQgLCwgoL?= =?us-ascii?q?4I4JAGCRwEEASMEGQEbHQEDAQsGBQs3AgIhAQERAQUBHAYTCIoUAQMNCJs4QIw?= =?us-ascii?q?UgW0YBQEcgwsFg2IKGScNWYJLAQEBAQEBBAEBAQEBGwIGEoRJghWBV4RgNoJrR?= =?us-ascii?q?ASFBoJlBYgBglILiHpgjyg+gkqNR1WFBpQtizCCfoknFAUggRc2gXIzGiNSMoF?= =?us-ascii?q?4gkYfgjAjN4woAQEB?= X-IronPort-AV: E=Sophos;i="5.46,441,1511823600"; d="scan'208,217";a="253182421" Received: from mail-it0-f46.google.com ([209.85.214.46]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 31 Jan 2018 22:35:36 +0100 Received: by mail-it0-f46.google.com with SMTP id n206so1333989itg.1 for ; Wed, 31 Jan 2018 13:35:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=oJSprV+77rK38YXHyTadZGjfJ4HzYkCHVDtGYo+Ap4Q=; b=UHYvVKjwHk1IDtS1IbAk+56oy/ls4meOt4OxdaUz0WyiSKIBG1AHrUIdQMuoD30qa2 2z/Y25AHAxeXXuEPbJLEN7VlB9H3Y/93hlXcsSdVeoIX2DPV3THO1NL6HQ4CEPiFb+k4 Ij14hoDMVHGeNGfZIrf6bP9jXHc7mdndHSqk+GXW6SDxJ6jjv1ZjveHzm+0cVbbPRgZ4 U9AD9Si7oxYYom1P0wbs/Z8Ql9AYTsMdbdDJNw4V0XLZLsOh/jr3sXY358hNOjJ5DwRN DI7ymfz8jPHPiglNXAjs8puKCOb9GVqFtx4/DT2rup6VaV4NAL2zC1DLCXCCi8AVOdi3 9x/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=oJSprV+77rK38YXHyTadZGjfJ4HzYkCHVDtGYo+Ap4Q=; b=qIss75TKTaJC21x+6fT/19ZPaKCJ1WZyBMUIPlV+Ksqq6uC6wQJpxvrgUk1hZaeA0+ ZVx5ZWUGQECHlQbPi46rvdtvS8uU2b7nitKctuUbbCgHo9PBVc6Vu432rA5TqsG5PhoK TsMomv15boMoELJA+VThjhRVvm3xNuY2f46HK2uvqaAuqrNDMXUlqzv+wwBCoqYqw+jV h1t13bqZ/Y4iibwWWt89nPUb4EwupoTgRTcHRzY1OCDW1w+ddmtRwqGRx7YI4NjKVS2K ltrEUWSBxV1dQ76pbYN6NpVATS8jYWo6PrMUcQlUAApAQd/onq2H8AA+b/6b/+WM+NlU grMw== X-Gm-Message-State: AKwxytfK/Q0AwiJ1M7JTs+/UKDegtcOwc+11CMj8xRIY2cihq4W65BGd Ovoa7pbR2kE3XT472dQhZcozMt9nMRx43GBygA== X-Google-Smtp-Source: AH8x227yPuesZ+2NfABuoIG5tSEqX8RXqAsNfrhEb+nqraMPfjuPYxoV7K9YZMp+uPdI2VUU0giaPQ0K9TR/rcTJrJM= X-Received: by 10.36.9.144 with SMTP id 138mr10908315itm.125.1517434534830; Wed, 31 Jan 2018 13:35:34 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.67.86 with HTTP; Wed, 31 Jan 2018 13:35:14 -0800 (PST) In-Reply-To: References: From: Yawar Amin Date: Wed, 31 Jan 2018 16:35:14 -0500 Message-ID: To: Lorenzo Pomili Cc: Ocaml Mailing List Content-Type: multipart/alternative; boundary="001a113fe74a6b28e8056419421e" Subject: Re: [Caml-list] Run time error on exception --001a113fe74a6b28e8056419421e Content-Type: text/plain; charset="UTF-8" Hi Lorenzo, On Wed, Jan 31, 2018 at 4:14 PM, Lorenzo Pomili wrote: > Friend of mine, pointed out to me a case in Reason who cause no compile > time error but run time error, I had reimplemented similar case in OCaml: > Runtime errors are very much possible in OCaml/Reason, OCaml does not make any guarantees about runtime errors in general. The only guarantee OCaml makes is that you won't get runtime *type* errors (with a couple of known exceptions). In other words, if your program compiles (passes typechecking) it won't throw a type error when it runs. exception Generic_exc;; > > let string_of_string s = string_of_int (int_of_string s) > > let foo = string_of_string "foo" > > let fun_exeption x = > match x with > 0 -> 0 > | _ -> raise Generic_exc > ;; > > let bar = string_of_int (fun_exeption 5) > > both foo and bar don't fail at compile time fail at run time, > Yeah, it makes sense that they don't fail at compile time, because they pass typechecking according to the OCaml typing rules. > me and my friend also try to reimplement similar case (the first one with > string and int) in Elm, and Elm compiler just say you have to manage > exeption, because function can actualy return exeption instead of int. > Elm tries to disallow *all* runtime errors (not just runtime type errors), so it uses various techniques like using the Maybe and Result types to indicate failed operations. And it makes you handle the possibility of failure up-front. This is really nice, and you can also do this in OCaml, but generally it is opt-in, e.g. you can use List.find (which raises an exception if it doesn't find the item) or List.find_opt (which returns an option containing the result of the list search). There is a compile params or similar for check this kind of error? is a > side effect of have a multi-paradigm? and if is it, how to manage it? > You have to manage it manually, and use various techniques to help. For example, there's a nice pattern-matching technique you can use to return values even after handling exceptions: let bar = string_of_int (match fun_exeption 5 with | int -> int | exception Generic_exc -> 0) > I belive I can use OCaml in functional way without just making attention > to not use side effect but if use of function like int_of_string can make > run time error, I probably approac to OCaml in wrong way, and I wanna > understand how to correct it. > OCaml is a mix between safety and pragmatism, it doesn't take the extreme safety approach that Elm does. There are ups and downs to both approaches, you would have to decide which is best for you. Regards, Yawar --001a113fe74a6b28e8056419421e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Lorenzo,

On Wed, Jan 31, 2018 at 4:14 PM, Lorenzo Pomili <loren= zo.pomili85@gmail.com> wrote:
Friend of mine, pointed out to me a case in Reason who = cause no compile time error but run time error, I had reimplemented similar= case in OCaml:

Runtime errors ar= e very much possible in OCaml/Reason, OCaml does not make any guarantees ab= out runtime errors in general. The only guarantee OCaml makes is that you w= on't get runtime type errors (with a couple of known exceptions)= . In other words, if your program compiles (passes typechecking) it won'= ;t throw a type error when it runs.

exception Generic_exc;;

let string_of= _string s =3D string_of_int (int_of_string s)

let foo =3D string_of_= string "foo"

let fun_exeption x =3D
=C2=A0=C2=A0=C2=A0 = match x with
=C2=A0=C2=A0=C2=A0 0 -> 0
=C2=A0=C2=A0=C2=A0 | _ ->= ; raise Generic_exc
;;

let bar =3D string_of_int (fun_exeption 5)=

both foo and bar don't fail at compile time fail at run time,

Yeah, it makes sense that they don'= ;t fail at compile time, because they pass typechecking according to the OC= aml typing rules.
=C2=A0
=
me and my friend also try to reimplement similar case (th= e first one with string and int) in Elm, and Elm compiler just say you have= to manage exeption, because function can actualy return exeption instead o= f int.

Elm tries to disallow a= ll runtime errors (not just runtime type errors), so it uses various te= chniques like using the Maybe and Result types to indicate failed operation= s. And it makes you handle the possibility of failure up-front. This is rea= lly nice, and you can also do this in OCaml, but generally it is opt-in, e.= g. you can use List.find (which raises an exception if it doesn't find = the item) or List.find_opt (which returns an option containing the result o= f the list search).

There is a compile params or similar for check this kind of er= ror? is a side effect of have a multi-paradigm? and if is it, how to manage= it?

You have to manage it manual= ly, and use various techniques to help. For example, there's a nice pat= tern-matching technique you can use to return values even after handling ex= ceptions:

=C2=A0 =C2=A0 let bar =3D string_of_int = (match fun_exeption 5 with
=C2=A0 =C2=A0 | int -> int
=C2=A0 =C2=A0 | exception Generic_exc -> 0)
=C2=A0
I belive I can use OCaml in fun= ctional way without just making attention to not use side effect but if use= of function like int_of_string can make run time error, I probably approac= to OCaml in wrong way, and I wanna understand how to correct it.

OCaml is a mix betw= een safety and pragmatism, it doesn't take the extreme safety approach = that Elm does. There are ups and downs to both approaches, you would have t= o decide which is best for you.

<= div class=3D"gmail_extra">Regards,

Yawar
--001a113fe74a6b28e8056419421e--