?
Solved

basic ML question

Posted on 2006-11-14
3
Medium Priority
?
247 Views
Last Modified: 2008-03-10
Can someone please explain to me what this statement is doing?

    fun zip f nil nul = nul |
        zip f (h::t)(i::s) = f(h,i)::zip f t s

I know fun zip means function zip() but I'm not sure what the rest of the ML syntax is doing here.

Thanks
0
Comment
Question by:DJ_AM_Juicebox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 24

Expert Comment

by:fridom
ID: 17945134
Well zip is  function taking three parameter the first line tells what happens if the parameter match
one of the lista are empty. I would be suprised however that nil = nul but that mayb  possible the second thing does a
destruction on the list if you have some_list then (h::rest) means h is the first element followed by the "rest" of the list
it does this for both parameters and after that it applies f to the both header elements and prepends them to the rest of the list applying this zip function
I have not ML installed here but Haskell and there you could use it this way:
my_zip f (x:xs) (y:ys) = f x y  : my_zip f xs ys
my_zip f _ _ = []

applied:
my_zip (+) [1,2,3] [3,2,1]
[4,4,4]

Regards
Friedrich
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 17948722
Hi fridom,

Where is zip being defined as taking three parameters? On the first line?

    fun zip f nil nul

What does 'f' stand for - and are 'nil' and 'nul' the second and third parameters, or are those reserved keywords?

I have a few more basic questions on this statement which I'll ask shortly. I come from C++ so I'm not new to programming just ML syntax.

Thanks
0
 
LVL 24

Accepted Solution

by:
fridom earned 2000 total points
ID: 17953741
fun is for declaring hey a function is comming f is obviously a function because you can see it from how it it used.
nil and null seems to stand for  an empty list, you can see that it must be lists from the other usage
(zip f (h::t)(i::s) = f(h,i)::zip f t s

so you can se f is applied two elements so it must be a function taking two arguments and returning one another
the h::t destructs a list into first element and the rest of list.

In Haskell you can type :type my_zip and it tells you what the parameters are I guess somethign like that exists in ML also

Regards
Friedrich
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question