FreshPorts -- The Place For Ports If you buy from Amazon USA, please support us by using this link.
Follow us
Blog
Twitter

I am looking for an LTO tape library. Do you have one to spare?
Help with ports
 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Newer Topic  |  Older Topic 
 Caml Functions i need help with
Author: P--K 
Date:   02-03-04 16:16

Hi Guys,

I am really stuck with some functions i wanna do in Caml can anybody help?

Define a function CountNi which takes a list of integers as its argument and returns the number of negative integers in the list.

And also...

Define a function CommonElement which takes two lists as its arguments
and then returns the list consisting of all common elements of them. For
example, when the two input lists are [1;2;3;4;5;6;7] and [1;3;5;7;9;11], the
result should be [1;3;5;7].

Cheers guys for any help



Reply To This Message
 
 Re: Caml Functions i need help with
Author: danp 
Date:   03-03-04 21:53

Sounds like a homework problem ... If you have specific questions, then you should ask those (maybe on a more appropriate forum ;). I'm not sure what help you are expecting here.

Here's how I'd think about the CountNi problem: As the problem states, you want a function that takes a list and returns a number. What can you do with a list? If you look at the example functions that you must surely have, you'll see that you can look at a list as a head and a tail. The head is an integer. It's easy to tell if an integer is negative or not. The tail is list. What can be done with that? [slams fist into hand] If only we had a function that counted the negative integers in a list -- oh, wait, CountNi does that. Sounds kind of recursive don't you think? ;) The preceding case handles everything except where there is no head, i.e. the empty list. It's easy to count the negative integers in an empty list.

The second problem sounds tricky ... It seems a little underspecified to me. Are you allowed to use library modules? I'm guessing that a particular module in the standard library might be useful.

Reply To This Message
 Forum List  |  Threaded View   Newer Topic  |  Older Topic 


 Forum List  |  Need a Login? Register Here 
 User Login
 User Name:
 Password:
 Remember my login:
   
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.


Servers and bandwidth provided by
New York Internet, SuperNews, and RootBSD
Valid HTML, CSS, and RSS.
Copyright © 2000-2014 Dan Langille. All rights reserved.