prova吧 关注:1贴子:32
  • 7回复贴,共1

Prova学习总结2

只看楼主收藏回复

Functional composition


IP属地:河南1楼2016-10-08 21:26回复
    4.Simple functional composition
    duplicate(X,[X,X]).
    %duplicate X : [X,X].
    %复制
    %Returns XX=6
    derive([[dulicate,add],3,XX])
    second_degree([A,B,C,X],R) :-
    R=A*X*X+B*X+C.


    IP属地:河南4楼2016-10-08 21:30
    回复
      5.Monadic functional composition
      1)The Maybe monad
      maybe(nothing())
      maybe (just (SomeData))
      eg:
      %输入是0,返回nothing
      %输入是数,折半几次,直到结果是nothing.
      halve_f 0 : maybe(nothing()) =!.
      halve_f Number.A : maybe(just(Number.B))=Number.B=Number.A/2.
      2)The List monad
      duplicate_m(X,list(X,X)).
      eg:
      % In Haskell: [1,2,3] >>= duplicate_m >>= duplicate_m
      % this returns X3=[list,1,1,1,1,2,2,2,2,3,3,3,3]
      :- solve(
      derive([[map(duplicate_m),join,map(duplicate_m),join],list(1,2, 3),X3])
      ).


      IP属地:河南5楼2016-10-08 21:32
      回复
        3)The state monad
        %初态
        真->大写
        假->小写
        flipcase([C,true],state([CM,false])):-
        CM=c.toUpperCase().
        flipcase([C,false],state([C,true])):-
        CM=C.toLowerCase().


        IP属地:河南6楼2016-10-08 21:33
        回复
          4)The Fact monad
          不改变事实,只产生新的事实
          eg:
          %data(1,2) -> data(1,3)
          %data(3,2) -> data(3,3)


          IP属地:河南7楼2016-10-08 21:34
          回复
            5)Combining monads
            6)Stream fusion and unfoldr


            IP属地:河南8楼2016-10-08 21:34
            回复
              1.12 Builtin reference
              assert/1 (i)
              %仅采用Prova list作为参数,作为事实添加到规则库中,对应提供列表的第一个元素。
              asserta/1 (i)
              %仅采用Prova list作为参数,针对相同的谓语,将之添加在任何事实之前。
              attach/3 (i,i,io)
              %1+2->3
              bound/1 (i)
              byte_stream/2 ([i,i],o)
              cache/2 (i)
              capture_enum/2 ([i,i],io) ND
              clone/2 (i,io)
              concat/2 (i, io)
              copy/2 (i,i)
              copy_stream/2 (i,o)
              consult/1 (i)
              element/2 (io,i) ND and element/3 (io,io,i) ND
              Implementation details
              fail/0 ()
              findall/3 (i,i,o)
              fopen/2 (i,o)
              for/2 (i,io) ND
              free/1 (i)
              listen/2 (i,i)
              match/3 (i,io,io)
              mklist/2 (i,io) ND
              parse_list/2 ([i,i],io)
              parse_nv/2 ([i,i],[io,io])
              println/1 (i) or println/2 (i,i)
              rcvMsg/5 (io,io,io,io,io)
              rcvMult/5 (io,io,io,io,io)
              read_enum/2 (i,io) ND
              retract/1 (i)
              retractall/1 (i)
              sendMsg/5 (io,i,i,i,i)
              sendMsgSync/5 (io,i,i,i,i)
              pawn/4 (io,i,i,i)
              tokenize_enum/2 ([i,i],io) ND
              tokenize_list/2 ([i,i],io)
              type/2 (i,io)
              unescape/2 (i,o)
              unique_id/1 (o)


              IP属地:河南9楼2016-10-08 21:39
              回复
                IP属地:河南10楼2016-10-08 21:40
                回复