Upgrade to Pro — share decks privately, control downloads, hide ads and more …

∃ PROLOG | PROLOG ∈ SCALA

∃ PROLOG | PROLOG ∈ SCALA

George Leontiev

October 23, 2014
Tweet

More Decks by George Leontiev

Other Decks in Technology

Transcript

  1. About me: @folone like types* *same reasons why @propensive does

    in his “Batshit crazy algebra with types” talk
  2. def validate[F[_], G, H, V <: HList, I <: HList,

    M <: HList, A <: HList, R](g: G)(v: V)(implicit hlG: FnHListerAux[G, A => R], zip: ZipApplyAux[V, I, M], mapped: MappedAux[A, F, M], unH: FnUnHListerAux[I => F[R], H], folder: LeftFolderAux[M, F[A => R], applier.type, F[HNil => R]], appl: Applicative[F]) = unH((in: I) => folder(zip(v, in), hlG(g).point[F]).map(_(HNil)))
  3. — Alan J. Perlis A language that doesn't affect the

    way you think about programming, is not worth knowing.
  4. Main principles It's all about formulating the question. Facts (ground

    terms) Rules (to generate more facts) RELATIONS > FUNCTIONS WHAT > HOW
  5. PREDICATES > FUNCTIONS Map inputs to outputs Run Return some

    output Define constraints Match Only return yes or no* *If "yes", they may add bindings to variables. log(2, 16, 4). log(2, 16) = 4
  6. NO.

  7. ?- depends(scala, prolog). no ?- depends(java, gcc). yes ?- depends(prolog,

    X). X = gcc. ?- depends(erlang, X). X = prolog ; X = clang. Questions
  8. Questions ?- depends(What, OnWhat). What = scala, OnWhat = java;

    What = java, OnWhat = gcc; What = ghc, OnWhat = clang; What = erlang, OnWhat = prolog; What = erlang, OnWhat = clang; What = prolog, OnWhat = gcc.
  9. common_dep(Pack1, Pack2) :- 
 depends(Pack1, Topic), 
 depends(Pack2, Topic), 


    Pack1 \== Pack2. ?- common_dep(java, What).
 What = prolog. Rules
  10. ?- deps_to_run(erl, What). What = erlang ; What = prolog

    ; What = clang ; What = gcc. Questions
  11. run(Command) :- findall(Dep, deps_to_run(Command, Dep), L), reverse(L, Deps), forall(member(Dep, Deps),

    install(Dep)), write('Running '), write_term(Command, []), write('\n'), !.
  12. ?- run(ghci). Installing clang Installing ghc Running ghci true. ?-

    run(erl). Installing gcc Installing prolog Installing erlang Running erl true.
  13. gcd(X, X, X). gcd(X, Y, Out) :- X < Y

    Z is Y - X gcd(X, Z, Out). gcd(X, Y, Out) :- Y < X, gcd(Y, X, Out). Prolog
  14. Facts — implicit vals. Rules — implicit defs taking implicit

    vals as parameters. Implication is the other way around.
  15. The more interesting your types get, the less fun it

    is to write them down. – Benjamin Pierce —
  16. • Scala does not perform the DFS. In case of

    multiple implicits, it does not compile. Prioritizing implicits via inheritance. • Diverging implicit expansion -Xlog-implicits. • Extremely hard to debug (pen and paper style). • Peculiar exceptions (SO in compiler, Method too large, etc.) Gotchas
  17. So now I need to redefine all the goodness from

    prolog stdlib?! Lists, naturals, etc. Shapeless: stdlib for logic programming in scala. —
  18. Promoting Functions to Type Families in Haskell HMonoid, HFunctor, HApplicative,

    HMonad Related Fun with type functions The art of Prolog Shapeless