/[svn]/types/types.ml
ViewVC logotype

Diff of /types/types.ml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 9 by abate, Tue Jul 10 16:57:14 2007 UTC revision 10 by abate, Tue Jul 10 16:57:27 2007 UTC
# Line 340  Line 340 
340  and sample_rec_arrow c =  and sample_rec_arrow c =
341    find sample_rec_arrow_aux c    find sample_rec_arrow_aux c
342    
343  and sample_rec_arrow_aux (left,right) =  and check_empty_simple_arrow_line left (s1,s2) =
   let single_right (s1,s2) =  
344      let rec aux accu1 accu2 = function      let rec aux accu1 accu2 = function
345        | (t1,t2)::left ->        | (t1,t2)::left ->
346            let accu1' = diff_t accu1 t1 in            let accu1' = diff_t accu1 t1 in
# Line 353  Line 352 
352      let accu1 = descr s1 in      let accu1 = descr s1 in
353      (is_empty accu1) ||      (is_empty accu1) ||
354      (try aux accu1 (diff any (descr s2)) left; true with NotEmpty -> false)      (try aux accu1 (diff any (descr s2)) left; true with NotEmpty -> false)
355    in  
356    if List.exists single_right right then raise Not_found  and check_empty_arrow_line left right =
357      List.exists (check_empty_simple_arrow_line left) right
358    
359    and sample_rec_arrow_aux (left,right) =
360      if (check_empty_arrow_line left right) then raise Not_found
361    else Fun left    else Fun left
362    
363    
# Line 366  Line 369 
369    List.fold_left aux [] fields    List.fold_left aux [] fields
370    
371  let get x = sample_rec Assumptions.empty x  let get x = sample_rec Assumptions.empty x
372    
373  end  end
374    
375    
# Line 547  Line 551 
551  let normalize n =  let normalize n =
552    internalize (rec_normalize (descr n))    internalize (rec_normalize (descr n))
553    
554    let apply_simple result left t =
555      let ok = ref false in
556      let rec aux result accu1 accu2 = function
557        | (t1,s1)::left ->
558            let result =
559              let accu1 = diff_t accu1 t1 in
560              if non_empty accu1 then aux result accu1 accu2 left
561              else (ok := true; result) in
562            let result =
563              let accu2 = cap_t accu2 s1 in
564              aux result accu1 accu2 left in
565            result
566        | [] ->
567            if subtype accu2 result
568            then result
569            else cup result accu2
570      in
571      let result = aux result t any left in
572      if !ok then result else raise Not_found
573    
574  let apply t1 t2 =  let apply t1 t2 =
575    failwith "apply: not yet implemented"    if is_empty t2
576      then empty
577      else
578        if non_empty {t1 with arrow = []}
579        then raise Not_found
580        else
581          List.fold_left
582            (fun accu (left,right) ->
583               if Sample.check_empty_arrow_line left right
584               then accu
585               else
586                 apply_simple accu left t2
587            )
588            empty
589            t1.arrow
590    
591    
592  module Print =  module Print =
# Line 643  Line 680 
680      Format.fprintf ppf "@[%a" print_descr d;      Format.fprintf ppf "@[%a" print_descr d;
681      end_print ppf      end_print ppf
682    
683      let rec print_sep f sep ppf = function
684        | [] -> ()
685        | [x] -> f ppf x
686        | x::rem -> f ppf x; Format.fprintf ppf "%s" sep; print_sep f sep ppf rem
687    
688    
689      let rec print_sample ppf = function
690        | Sample.Int i -> Format.fprintf ppf "%i" i
691        | Sample.Atom a -> Format.fprintf ppf "`%s" (atom_name a)
692        | Sample.String s -> Format.fprintf ppf "%S" s
693        | Sample.Pair (x1,x2) ->
694            Format.fprintf ppf "(%a,%a)"
695            print_sample x1
696            print_sample x2
697        | Sample.Record r ->
698            Format.fprintf ppf "{ %a }"
699              (print_sep
700                 (fun ppf (l,x) ->
701                    Format.fprintf ppf "%s = %a"
702                    (label_name l)
703                    print_sample x
704                 )
705                 " ; "
706              ) r
707        | Sample.Fun iface ->
708            Format.fprintf ppf "(fun ( %a ) x -> ...)"
709              (print_sep
710                 (fun ppf (t1,t2) ->
711                    Format.fprintf ppf "%a -> %a; "
712                    print t1 print t2
713                 )
714                 " ; "
715              ) iface
716  end  end
717    
718  (*  (*

Legend:
Removed from v.9  
changed lines
  Added in v.10

CVS Admin">CVS Admin
ViewVC Help
Powered by ViewVC 1.1.5