src/Pure/General/seq.ML
changeset 11721 0d60622b668f
parent 8806 a202293db3f6
child 12851 e87496286934
equal deleted inserted replaced
11720:5341e38309e8 11721:0d60622b668f
    15   val make: (unit -> ('a * 'a seq) option) -> 'a seq
    15   val make: (unit -> ('a * 'a seq) option) -> 'a seq
    16   val pull: 'a seq -> ('a * 'a seq) option
    16   val pull: 'a seq -> ('a * 'a seq) option
    17   val empty: 'a seq
    17   val empty: 'a seq
    18   val cons: 'a * 'a seq -> 'a seq
    18   val cons: 'a * 'a seq -> 'a seq
    19   val single: 'a -> 'a seq
    19   val single: 'a -> 'a seq
       
    20   val try: ('a -> 'b) -> 'a -> 'b seq
    20   val hd: 'a seq -> 'a
    21   val hd: 'a seq -> 'a
    21   val tl: 'a seq -> 'a seq
    22   val tl: 'a seq -> 'a seq
    22   val chop: int * 'a seq -> 'a list * 'a seq
    23   val chop: int * 'a seq -> 'a list * 'a seq
    23   val list_of: 'a seq -> 'a list
    24   val list_of: 'a seq -> 'a list
    24   val of_list: 'a list -> 'a seq
    25   val of_list: 'a list -> 'a seq
    71 
    72 
    72 (*head and tail -- beware of calling the sequence function twice!!*)
    73 (*head and tail -- beware of calling the sequence function twice!!*)
    73 fun hd xq = #1 (the (pull xq))
    74 fun hd xq = #1 (the (pull xq))
    74 and tl xq = #2 (the (pull xq));
    75 and tl xq = #2 (the (pull xq));
    75 
    76 
       
    77 (*partial function as procedure*)
       
    78 fun try f x =
       
    79   (case Library.try f x of
       
    80     Some y => single y
       
    81   | None => empty);
       
    82 
    76 
    83 
    77 (*the list of the first n elements, paired with rest of sequence;
    84 (*the list of the first n elements, paired with rest of sequence;
    78   if length of list is less than n, then sequence had less than n elements*)
    85   if length of list is less than n, then sequence had less than n elements*)
    79 fun chop (n, xq) =
    86 fun chop (n, xq) =
    80   if n <= 0 then ([], xq)
    87   if n <= 0 then ([], xq)