ocaml学习随笔-1

    xiaoxiao2021-03-25  90

    utop # let rec my_listprint items =

    match items with

    |first::the_rest->printf "%s\n" first;

    my_listprint the_rest

    |[]->""

    ;;

    val my_listprint : string list -> string = <fun>                                ─( 21:48:03 )─< command 27 >─────────────────────────────────────{ counter: 0 }─utop # my_listprint ["aaa";"nnnn";"bbbb"];;

    aaa     

    nnnn

    bbbb                                                                            

    - : string = ""                                                                 ─( 21:48:13 )─< command 28 >─────────────────────────────────────{ counter: 0 }─utop

    utop # let my_first items=match

    items with 

    |first::the_rest->first

    |[]->"null"(*空*)

    ;;

    val my_first : string list -> string = <fun>                                    ─(                          ─( 20:35:09 )─< command 3 >──────────────────────────────────────{ counter: 0 }─

    utop # my_first ["one";"two";"three";"four"];;

    - : string = "one" 

    转载请注明原文地址: https://ju.6miu.com/read-6810.html

    最新回复(0)