[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: composing projections



> 
> I'd like to compose projections. 
> For example, given a list of tuples of lists I want to map a function that
> finds the length of the first lists in each tuple:
> 
> map ((length o proj1) my_tuple)
> 
> But this generates the error: "Projection expressions may only appear as
> operators of an application."
> 
> Can anyone suggest a way to accomplish this?
> 
> thanks,
> 
> Ben Kleinman
> bkleinman@writeme.com
> http://www.dcs.ed.ac.uk/home/bkk
> 
> 

A hack solution is to define your own projection function in terms of
PROJ_1.

I tried writing the spec as you described, got your error, replaced
PROJ_1 with my own projection function, and got it to work.  I've
appended my spec below.

I'm sure there's a better solution though.

John


mapping_tuples_of_lists  % [ parameters ]
		: THEORY

  BEGIN

  % ASSUMING
   % assuming declarations
  % ENDASSUMING




  int_list : TYPE = list[int]
  tuple_list : TYPE = [int_list, int_list]

  importing list_adt_map

  my_proj(t_l : tuple_list) : int_list = PROJ_1(t_l)
  
  foo_t : TYPE = list[tuple_list]

  b : foo_t

  b_length : int = length(map[tuple_list, int_list](my_proj,b))

  END mapping_tuples_of_lists


==============================++====================
Dr. John Hoffman              ||                    
Secure Computing Corporation  || What do you want to
2675 Long Lake Road           || read for, when you 
Roseville, MN  55124          || can watch TV?      
hoffman@securecomputing.com   ||                    
Fax  :(612)628-2701           ||  - Matilda's Father
Phone:(612)628-2808           ||                    
==============================++====================