Re: What does TYPE SAFE mean?

"Sergei Steshenko [email protected] [ocaml_beginners]" <[email protected]> Sun, 14 Feb 2016 09:56:55 +0000 (UTC)
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>
"Supposedly the problem with Python, Ruby, Perl, Matlab, Mathematica, Maple and other dynamic languages is that because of how these languages are set up there is a greater risk of unexpected runtime errors.  Is that correct?  Or did I just get lost down a rabbit hole?" - yes, you correctly identified the problem.
In Perl, however, there is attributes - perldoc.perl.org , 

|   |
|   |   |   |   |   |
| attributes - perldoc.perl.orgPlease note: Many features of this site require JavaScript. You appear to have JavaScript disabled, or are running a non-JavaScript capable web browser.  |
|  |
| View on perldoc.perl.org | Preview by Yahoo |
|  |
|   |

and
Type checking with Moo

|   |
|   |  |   |   |   |   |   |
| Type checking with Moowas never reached. Let's see what happens when the incorrect value is already provided in the constructor: examples/mootype/student_2.pl use strict; us... |
|  |
| View on perlmaven.com | Preview by Yahoo |
|  |
|   |


which, of course very CPU intensive and still runtime, but nonetheless.
OTOH, I started writing something similar to Perl data structures for OCaml (but dropped it). The idea is pretty freehand creation of data structures - not declaring types explicitly and instead relying on type inference. Once entities in the data structure are created, they will retain type due to OCaml type strictness. For example, if one creates a hash key named "number" and assigns to it the value of 2, it won't be possible in the future to assign the "two" value to the same key since "two" is a string and not an integer - unlike in Perl.
This type freedom in the beginning and type strictness in the end is a design goal.
--Sergei.
 
      From: "Douglas Lewit [email protected] [ocaml_beginners]" <[email protected]>
 To: [email protected] 
 Sent: Sunday, February 14, 2016 9:08 AM
 Subject: Re: "ocaml_beginners"::[] What does TYPE SAFE mean?
   
    So my guess is that if a language is very "type safe" then most errors should be caught at compile time and thus there should be very few runtime errors?  Supposedly the problem with Python, Ruby, Perl, Matlab, Mathematica, Maple and other dynamic languages is that because of how these languages are set up there is a greater risk of unexpected runtime errors.  Is that correct?  Or did I just get lost down a rabbit hole?
I really enjoy how Ocaml is used to generate recursive functions that act on lists.  This of course is not really unique to Ocaml, but working with Ocaml has really helped me to appreciate the power of recursion.  I'm guessing that recursion is unavoidable and extremely important in any functional language, whether it's Ocaml or Scala or Haskell or F# or anything else.  ( I believe that Wolfram Mathematica contains some programming constructs that are of a functional nature as well.  Maple and Matlab however are mostly imperative. )

On Sat, Feb 13, 2016 at 9:15 AM, Hendrik Boom [email protected] [ocaml_beginners] <[email protected]> wrote:

     On Sat, Feb 13, 2016 at 01:01:31AM -0600, Douglas Lewit [email protected] [ocaml_beginners] wrote:
> What do people mean when they say that Ocaml is a "type safe" language?

To put it very informally, it means that every variable and expression 
has a type (such as int, or int->int etc.) and that during execution, 
you are guaranteed that the values of these variables and expressions 
are indeed values of the correct types.

The compiler will prevent anything violating these constraints from 
getting through to execution. Though occasionally, as a real-world 
compromise, there will have to be run-time checks. And, occasionally, 
oe must escape to code not written on OCaml, and then the OCaml 
compiler cannot ensure type-correctness.

-- hendrik
   

  #yiv4225583281 #yiv4225583281 -- #yiv4225583281ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv4225583281 #yiv4225583281ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv4225583281 #yiv4225583281ygrp-mkp #yiv4225583281hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv4225583281 #yiv4225583281ygrp-mkp #yiv4225583281ads {margin-bottom:10px;}#yiv4225583281 #yiv4225583281ygrp-mkp .yiv4225583281ad {padding:0 0;}#yiv4225583281 #yiv4225583281ygrp-mkp .yiv4225583281ad p {margin:0;}#yiv4225583281 #yiv4225583281ygrp-mkp .yiv4225583281ad a {color:#0000ff;text-decoration:none;}#yiv4225583281 #yiv4225583281ygrp-sponsor #yiv4225583281ygrp-lc {font-family:Arial;}#yiv4225583281 #yiv4225583281ygrp-sponsor #yiv4225583281ygrp-lc #yiv4225583281hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv4225583281 #yiv4225583281ygrp-sponsor #yiv4225583281ygrp-lc .yiv4225583281ad {margin-bottom:10px;padding:0 0;}#yiv4225583281 #yiv4225583281actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv4225583281 #yiv4225583281activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv4225583281 #yiv4225583281activity span {font-weight:700;}#yiv4225583281 #yiv4225583281activity span:first-child {text-transform:uppercase;}#yiv4225583281 #yiv4225583281activity span a {color:#5085b6;text-decoration:none;}#yiv4225583281 #yiv4225583281activity span span {color:#ff7900;}#yiv4225583281 #yiv4225583281activity span .yiv4225583281underline {text-decoration:underline;}#yiv4225583281 .yiv4225583281attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv4225583281 .yiv4225583281attach div a {text-decoration:none;}#yiv4225583281 .yiv4225583281attach img {border:none;padding-right:5px;}#yiv4225583281 .yiv4225583281attach label {display:block;margin-bottom:5px;}#yiv4225583281 .yiv4225583281attach label a {text-decoration:none;}#yiv4225583281 blockquote {margin:0 0 0 4px;}#yiv4225583281 .yiv4225583281bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv4225583281 .yiv4225583281bold a {text-decoration:none;}#yiv4225583281 dd.yiv4225583281last p a {font-family:Verdana;font-weight:700;}#yiv4225583281 dd.yiv4225583281last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv4225583281 dd.yiv4225583281last p span.yiv4225583281yshortcuts {margin-right:0;}#yiv4225583281 div.yiv4225583281attach-table div div a {text-decoration:none;}#yiv4225583281 div.yiv4225583281attach-table {width:400px;}#yiv4225583281 div.yiv4225583281file-title a, #yiv4225583281 div.yiv4225583281file-title a:active, #yiv4225583281 div.yiv4225583281file-title a:hover, #yiv4225583281 div.yiv4225583281file-title a:visited {text-decoration:none;}#yiv4225583281 div.yiv4225583281photo-title a, #yiv4225583281 div.yiv4225583281photo-title a:active, #yiv4225583281 div.yiv4225583281photo-title a:hover, #yiv4225583281 div.yiv4225583281photo-title a:visited {text-decoration:none;}#yiv4225583281 div#yiv4225583281ygrp-mlmsg #yiv4225583281ygrp-msg p a span.yiv4225583281yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv4225583281 .yiv4225583281green {color:#628c2a;}#yiv4225583281 .yiv4225583281MsoNormal {margin:0 0 0 0;}#yiv4225583281 o {font-size:0;}#yiv4225583281 #yiv4225583281photos div {float:left;width:72px;}#yiv4225583281 #yiv4225583281photos div div {border:1px solid #666666;height:62px;overflow:hidden;width:62px;}#yiv4225583281 #yiv4225583281photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv4225583281 #yiv4225583281reco-category {font-size:77%;}#yiv4225583281 #yiv4225583281reco-desc {font-size:77%;}#yiv4225583281 .yiv4225583281replbq {margin:4px;}#yiv4225583281 #yiv4225583281ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv4225583281 #yiv4225583281ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv4225583281 #yiv4225583281ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv4225583281 #yiv4225583281ygrp-mlmsg select, #yiv4225583281 input, #yiv4225583281 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv4225583281 #yiv4225583281ygrp-mlmsg pre, #yiv4225583281 code {font:115% monospace;}#yiv4225583281 #yiv4225583281ygrp-mlmsg * {line-height:1.22em;}#yiv4225583281 #yiv4225583281ygrp-mlmsg #yiv4225583281logo {padding-bottom:10px;}#yiv4225583281 #yiv4225583281ygrp-msg p a {font-family:Verdana;}#yiv4225583281 #yiv4225583281ygrp-msg p#yiv4225583281attach-count span {color:#1E66AE;font-weight:700;}#yiv4225583281 #yiv4225583281ygrp-reco #yiv4225583281reco-head {color:#ff7900;font-weight:700;}#yiv4225583281 #yiv4225583281ygrp-reco {margin-bottom:20px;padding:0px;}#yiv4225583281 #yiv4225583281ygrp-sponsor #yiv4225583281ov li a {font-size:130%;text-decoration:none;}#yiv4225583281 #yiv4225583281ygrp-sponsor #yiv4225583281ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv4225583281 #yiv4225583281ygrp-sponsor #yiv4225583281ov ul {margin:0;padding:0 0 0 8px;}#yiv4225583281 #yiv4225583281ygrp-text {font-family:Georgia;}#yiv4225583281 #yiv4225583281ygrp-text p {margin:0 0 1em 0;}#yiv4225583281 #yiv4225583281ygrp-text tt {font-size:120%;}#yiv4225583281 #yiv4225583281ygrp-vital ul li:last-child {border-right:none !important;}#yiv4225583281