Giter VIP home page Giter VIP logo

ct_from_programmers.scala's Introduction

Scala sample code for Bartosz Milewski's Category Theory for Programmers

Build Status Gitter

WIP

Contributing

Any contribution (PR, review, issues) will be more than welcome! If you are interested, please indicate that you are working on a certain section in the respective issue. You can find the issues here..

To compile

sbt tut

Style guide

Use ```tut:silent``` for code that is compilable, use ```scala``` otherwise.

Use a line of ............. to separate between code examples.

There are multiple ways to translate haskell code into scala. For scala syntax, generally speaking we follow the common styles in FP scala codebase (e.g. typelevel/cats)

functions vs. methods

If it's a "standalone" function, use the function syntax, i.e.

val f: A => B = ???

If it is inside a trait or class, use the method, i.e.

def f(a: A) : B = ???

Currying

Follow the common strategies in FP codebases, roughly

  • if there is one function parameter, create a dedicated parameter list for it and make it the last parameter list.
  • if there are multiple function parameters, group them together, and put them in a dedicated last parameter list.
  • of course, implicit parameters have to go in a separate parameter list
  • everything else should go to a single parameter list.
  • if the haskell code partially applied the function, partially apply with underscore in scala code.

Infix syntax for type class methods

Create a XXXOps implicit extension class to support such infix syntax. E.g. To support (m1: A => Writer[B]) >=> (m2: B => Writer[C]) add

  implicit class Kleisli[A, B](m1: A => Writer[B]) {
   def >=>[C](m2: B => Writer[C]): A => Writer[C] = ...

Indentation and line break

Use 2 space indentation and prefer to aggressively break lines

def >=>[C](m2: B => Writer[C]): A => Writer[C] 
   = { x => 
     ...
   }

If the signature is too long, we break it to multiple lines as well. Control each line to be within 45 characters.

Symbol names

For the prime symbole, use U+16CC RUNIC LETTER SHORT-TWIG-SOL S แ›Œ, it works with scalac while the unicode prime symbole doesn't

License

CC image

This work is licensed under a Creative Commons Attribution 4.0 International License.

ct_from_programmers.scala's People

Contributors

avasil avatar kailuowang avatar systemfw avatar zelenya avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.