Re: I like this but I'm getting a warning message.

"Kenneth Miller [email protected] [ocaml_beginners]" <[email protected]> Wed, 23 Mar 2016 17:05:28 +0000 (UTC)
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>
Well actually if everything works fine, just delete that line. In fact, it might be better if you turned warnings into errors, because it requires you to think about your program more. The functional and strongly typed communities have a big place in their hearts for correctness. If you take your warnings to any of those communities, they'll tell you that the compiler was engineered with rigor in mind. 

OCaml probably isn't more popular because it is hard. The compiler won't put up so much will other stuff, whereas Java/python/xyz will run will all manner of wrong input. It just blows up when it hits it, preventing you from finding errors at compile time but allowing you to move forward for the time being with your assignment.

Thinking about math isn't what very many people want to do with their time because it's hard, you're going to have to acknowledge that. Rigor is what it is: rigor.  

    On Wednesday, March 23, 2016 12:55 PM, "Douglas Lewit [email protected] [ocaml_beginners]" <[email protected]> wrote:
 

     Ken,
Thanks!  I'll see what I can do to fix it.  It's probably not a big deal because everything still works okay.  I just hope INRIA never turns that warning message into an error message that blocks compilation.  Then THAT would be a real problem!
Also, a quick question here.  Where I go to school Java is the #1 language.  Not a bad choice at all.  I think Java rocks, but there are other languages of course.  In my CS department Python is the #2 language.  Why hasn't Ocaml become more popular?  It's actually an interesting language, and can really help CS students break through the "recursion barrier" that makes the Data Structures course insurmountably difficult for some students.
Best,
Douglas.

On Wed, Mar 23, 2016 at 11:39 AM, Kenneth Miller [email protected] [ocaml_beginners] <[email protected]> wrote:

     I'm guessing that at the line:getFrequency n lst ; 

You're discarding the value resolved by that function call - it will not get used, and the computation will be wasted because the garbage collector will munch it up. The compiler is telling you that unit is the type it should return, because it resumes that if you call a function with a non-unit return value, that that unit is something that you should pay attention to, or explicitly tell the compiler to shut up with Pervasives.ignore.
 

    On Wednesday, March 23, 2016 12:34 PM, "Douglas Lewit [email protected] [ocaml_beginners]" <[email protected]> wrote:
 

     Hi everyone,
I wrote these functions, and they are pretty good in my humble opinion.  ( Forgive the lack of modesty, but I really worked hard on these. )
However, I'm getting "Warning 10: this function should have output unit( )" or something like that.
Is that really a bad thing?  Is there a workaround?  Thanks for sharing.
(* Use the following functions to get the frequencies from a list. *)
let get_frequency n lst = let count = ref 0 in let rec getFrequency m l = match l with |[ ] -> [ ]|head :: tail -> if head = m then begin incr count ; getFrequency m tail end else getFrequency m tail in getFrequency n lst ; [ n ; !count ] ;;
let rec makeSet lst = let rec mem num l = match l with |[ ] -> false|head :: tail -> if head = num then true else mem num tail in match lst with |[ ] -> [ ]|head :: tail -> if mem head tail then makeSet tail else head :: ( makeSet tail ) ;;
let frequency_list lst = let set = makeSet lst in let rec freq_list s l = match s with |[ ] -> [ ]|head :: tail -> ( get_frequency head l ) :: ( freq_list tail l ) in freq_list ( List.sort compare set ) lst ;;
(* Use the following function to generate a list of random integers between "lower" and "upper", inclusive. *)let rec random_sequence lower upper size = if size = 0 then [ ] else ( lower + Random.int( upper - lower + 1 ) ) :: ( random_sequence lower upper ( size - 1 ) ) ;;
So for example, if I apply the function frequency_list to [ 1; 1; 1; 1; 1; 2; 2; 2; 2; 2; 2 ] Ocaml should return[ [1; 5] ; [2; 6] ] ( Interpretation: The original list contains 5 1's and 6 2's. )
Thanks for the help!  I really struggled with this one.  There could be an easier way to find the frequencies of a list, but that's my solution to the problem.  It works!  But not sure how really "efficient" or fast my code is compared to other solutions to the same problem.
Best,
Douglas.
  

      

  #yiv3344702659 #yiv3344702659 -- #yiv3344702659ygrp-mkp {border:1px solid #d8d8d8;font-family:Arial;margin:10px 0;padding:0 10px;}#yiv3344702659 #yiv3344702659ygrp-mkp hr {border:1px solid #d8d8d8;}#yiv3344702659 #yiv3344702659ygrp-mkp #yiv3344702659hd {color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px 0;}#yiv3344702659 #yiv3344702659ygrp-mkp #yiv3344702659ads {margin-bottom:10px;}#yiv3344702659 #yiv3344702659ygrp-mkp .yiv3344702659ad {padding:0 0;}#yiv3344702659 #yiv3344702659ygrp-mkp .yiv3344702659ad p {margin:0;}#yiv3344702659 #yiv3344702659ygrp-mkp .yiv3344702659ad a {color:#0000ff;text-decoration:none;}#yiv3344702659 #yiv3344702659ygrp-sponsor #yiv3344702659ygrp-lc {font-family:Arial;}#yiv3344702659 #yiv3344702659ygrp-sponsor #yiv3344702659ygrp-lc #yiv3344702659hd {margin:10px 0px;font-weight:700;font-size:78%;line-height:122%;}#yiv3344702659 #yiv3344702659ygrp-sponsor #yiv3344702659ygrp-lc .yiv3344702659ad {margin-bottom:10px;padding:0 0;}#yiv3344702659 #yiv3344702659actions {font-family:Verdana;font-size:11px;padding:10px 0;}#yiv3344702659 #yiv3344702659activity {background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}#yiv3344702659 #yiv3344702659activity span {font-weight:700;}#yiv3344702659 #yiv3344702659activity span:first-child {text-transform:uppercase;}#yiv3344702659 #yiv3344702659activity span a {color:#5085b6;text-decoration:none;}#yiv3344702659 #yiv3344702659activity span span {color:#ff7900;}#yiv3344702659 #yiv3344702659activity span .yiv3344702659underline {text-decoration:underline;}#yiv3344702659 .yiv3344702659attach {clear:both;display:table;font-family:Arial;font-size:12px;padding:10px 0;width:400px;}#yiv3344702659 .yiv3344702659attach div a {text-decoration:none;}#yiv3344702659 .yiv3344702659attach img {border:none;padding-right:5px;}#yiv3344702659 .yiv3344702659attach label {display:block;margin-bottom:5px;}#yiv3344702659 .yiv3344702659attach label a {text-decoration:none;}#yiv3344702659 blockquote {margin:0 0 0 4px;}#yiv3344702659 .yiv3344702659bold {font-family:Arial;font-size:13px;font-weight:700;}#yiv3344702659 .yiv3344702659bold a {text-decoration:none;}#yiv3344702659 dd.yiv3344702659last p a {font-family:Verdana;font-weight:700;}#yiv3344702659 dd.yiv3344702659last p span {margin-right:10px;font-family:Verdana;font-weight:700;}#yiv3344702659 dd.yiv3344702659last p span.yiv3344702659yshortcuts {margin-right:0;}#yiv3344702659 div.yiv3344702659attach-table div div a {text-decoration:none;}#yiv3344702659 div.yiv3344702659attach-table {width:400px;}#yiv3344702659 div.yiv3344702659file-title a, #yiv3344702659 div.yiv3344702659file-title a:active, #yiv3344702659 div.yiv3344702659file-title a:hover, #yiv3344702659 div.yiv3344702659file-title a:visited {text-decoration:none;}#yiv3344702659 div.yiv3344702659photo-title a, #yiv3344702659 div.yiv3344702659photo-title a:active, #yiv3344702659 div.yiv3344702659photo-title a:hover, #yiv3344702659 div.yiv3344702659photo-title a:visited {text-decoration:none;}#yiv3344702659 div#yiv3344702659ygrp-mlmsg #yiv3344702659ygrp-msg p a span.yiv3344702659yshortcuts {font-family:Verdana;font-size:10px;font-weight:normal;}#yiv3344702659 .yiv3344702659green {color:#628c2a;}#yiv3344702659 .yiv3344702659MsoNormal {margin:0 0 0 0;}#yiv3344702659 o {font-size:0;}#yiv3344702659 #yiv3344702659photos div {float:left;width:72px;}#yiv3344702659 #yiv3344702659photos div div {border:1px solid #666666;height:62px;overflow:hidden;width:62px;}#yiv3344702659 #yiv3344702659photos div label {color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}#yiv3344702659 #yiv3344702659reco-category {font-size:77%;}#yiv3344702659 #yiv3344702659reco-desc {font-size:77%;}#yiv3344702659 .yiv3344702659replbq {margin:4px;}#yiv3344702659 #yiv3344702659ygrp-actbar div a:first-child {margin-right:2px;padding-right:5px;}#yiv3344702659 #yiv3344702659ygrp-mlmsg {font-size:13px;font-family:Arial, helvetica, clean, sans-serif;}#yiv3344702659 #yiv3344702659ygrp-mlmsg table {font-size:inherit;font:100%;}#yiv3344702659 #yiv3344702659ygrp-mlmsg select, #yiv3344702659 input, #yiv3344702659 textarea {font:99% Arial, Helvetica, clean, sans-serif;}#yiv3344702659 #yiv3344702659ygrp-mlmsg pre, #yiv3344702659 code {font:115% monospace;}#yiv3344702659 #yiv3344702659ygrp-mlmsg * {line-height:1.22em;}#yiv3344702659 #yiv3344702659ygrp-mlmsg #yiv3344702659logo {padding-bottom:10px;}#yiv3344702659 #yiv3344702659ygrp-msg p a {font-family:Verdana;}#yiv3344702659 #yiv3344702659ygrp-msg p#yiv3344702659attach-count span {color:#1E66AE;font-weight:700;}#yiv3344702659 #yiv3344702659ygrp-reco #yiv3344702659reco-head {color:#ff7900;font-weight:700;}#yiv3344702659 #yiv3344702659ygrp-reco {margin-bottom:20px;padding:0px;}#yiv3344702659 #yiv3344702659ygrp-sponsor #yiv3344702659ov li a {font-size:130%;text-decoration:none;}#yiv3344702659 #yiv3344702659ygrp-sponsor #yiv3344702659ov li {font-size:77%;list-style-type:square;padding:6px 0;}#yiv3344702659 #yiv3344702659ygrp-sponsor #yiv3344702659ov ul {margin:0;padding:0 0 0 8px;}#yiv3344702659 #yiv3344702659ygrp-text {font-family:Georgia;}#yiv3344702659 #yiv3344702659ygrp-text p {margin:0 0 1em 0;}#yiv3344702659 #yiv3344702659ygrp-text tt {font-size:120%;}#yiv3344702659 #yiv3344702659ygrp-vital ul li:last-child {border-right:none !important;}#yiv3344702659