caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Lorenzo Pomili <lorenzo.pomili85@gmail.com>
To: Malcolm Matalka <mmatalka@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Run time error on exception
Date: Sun, 4 Feb 2018 19:14:14 +0100	[thread overview]
Message-ID: <CALJ6Lmh1-Tu89T3N6es4u+9cKDq=rGH=VuhabZJmNHHse+P59w@mail.gmail.com> (raw)
In-Reply-To: <86wozxmbhm.fsf@gmail.com>

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

Thanks for reply, one more question there is a way in OCaml, for know if
function can produce side effects? I mean automatic way not read
documentation or source code ^^"

2018-02-01 8:10 GMT+01:00 Malcolm Matalka <mmatalka@gmail.com>:

> Exceptions basically mean "runtime error".  This is why some APIs use
> the result type instead of exceptions.  So the API could be something
> like:
>
> val int_of_string : string -> (int, err) result
>
> where err is some error type.
>
> I wrote a blog post about this years ago, the APIs in it might be out
> dated but the general concept is probably still applies:
>
> http://functional-orbitz.blogspot.se/2013/01/experiences-using-resultt-vs-
> exceptions.html
>
> Lorenzo Pomili <lorenzo.pomili85@gmail.com> writes:
>
> > 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:
> >
> >
> >
> > 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, 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.
> >
> > 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?
> >
> > 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.
>
>

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

  reply	other threads:[~2018-02-04 18:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-31 21:14 Lorenzo Pomili
2018-01-31 21:35 ` Yawar Amin
2018-02-01  7:10 ` Malcolm Matalka
2018-02-04 18:14   ` Lorenzo Pomili [this message]
2018-02-05 10:49     ` Malcolm Matalka
2018-02-05 15:26     ` Yawar Amin

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='CALJ6Lmh1-Tu89T3N6es4u+9cKDq=rGH=VuhabZJmNHHse+P59w@mail.gmail.com' \
    --to=lorenzo.pomili85@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=mmatalka@gmail.com \
    /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).