3 Replies - 491 Views - Last Post: 24 December 2011 - 04:26 PM Rate Topic: -----

Topic Sponsor:

#1 Nady990  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 21-November 11

question : ML LANGUAGE

Posted 24 December 2011 - 01:03 PM

i wrote this code :

datatype 'a Multilist = t1 of 'a list 
                       |t2 of 'a Multilist list ;
fun h num [] = []
	|h num (x::xs) = (x,num)::h num xs ; 

fun f(n,(t1 l)) = h(n,l) 
   |f(n,(t2 l)) = f(n+1,hd l) @ f(n,tl l); 





and i get this error :
operator and operand don't agree in the expression f(n,(t1 l)) and in f(n+1,hd l) @ f(n,tl l)
but i dont understand why i get this errors ?

Is This A Good Question/Topic? 0
  • +

Replies To: question : ML LANGUAGE

#2 sepp2k  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 619
  • View blog
  • Posts: 1,035
  • Joined: 21-June 11

Re: question : ML LANGUAGE

Posted 24 December 2011 - 03:34 PM

First of all; You define h to take two arguments: an element and a list. However you try to call it with a single argument: the tuple (n,l). You should call it as h n l instead (or define it to take a tuple like you did with f).

Secondly the argument to f should be a tuple whose second element is of type MultiList. When you call it as f(n+1,hd l) that's fine because hd l is a MultiList. However f(n, tl l] is wrong because tl l is a list of MultiLists, not a single MultiList.
Was This Post Helpful? 0
  • +
  • -

#3 Nady990  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 21-November 11

Re: question : ML LANGUAGE

Posted 24 December 2011 - 03:56 PM

now i wrote it this way :

fun f(n,(type1 l)) = h n l 
   |f(n,(type2 ls)) = f(n+1,hd ls) @ g(n,tl ls) 

 and g n [] = [] 
    |g n (type2 l)::ls) = f(n,l) @ g(n+1,ls) ; 



and i got this error : deleting RPAREN EQUALLOP , what does it mean ?
Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 619
  • View blog
  • Posts: 1,035
  • Joined: 21-June 11

Re: question : ML LANGUAGE

Posted 24 December 2011 - 04:26 PM

If the compiler says "deleting SOMETOKEN" that means it encountered a SOMETOKEN where it did not expect one. In this case it's complaining about a closing parentheses (RPAREN == Right PARENthesis == closing parenthesis). If you look at line 5, you'll see that there's two closing parentheses, but only one opening parenthesis, so it's no wonder the compiler is confused.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1