Coder Social home page Coder Social logo

thma / ltupatternfactory Goto Github PK

View Code? Open in Web Editor NEW
980.0 27.0 39.0 602 KB

Lambda the ultimate Pattern Factory: FP, Haskell, Typeclassopedia vs Software Design Patterns

License: Apache License 2.0

Haskell 100.00%
functional-languages factory-pattern strategy-pattern builder-pattern function-composition iterator-pattern monad haskell design-patterns gof-patterns

ltupatternfactory's People

Contributors

camhashemi avatar philipcraig avatar renovate-bot avatar thma avatar tysonmn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ltupatternfactory's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/haskell.yml
  • actions/checkout v2
  • actions/setup-haskell v1
  • actions/cache v1

  • Check this box to trigger a request for Renovate to run again on this repository

Strategy pattern misrepresented to be the client of a strategy

The explanation starts off well, comparing the strategy design pattern to function pointers in structured programming, interfaces in OO and higher order functions in FP, but it derailed by shifting attention to the client of a strategy and ultimately comparing it to functors and concluding: "namely the injecting of a function into a computational context and its execution in this context".

As stated in GoF under the Strategy Design Pattern:

"Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it."

Attention to "encapsulates" and "lets the algorithm vary independently from clients that use it". By "use it" we should understand to make a call or to execute such algorithm. A few sections down we read:

"We can avoid these problems by defining classes that encapsulate different linebreaking algorithms. An algorithm that's encapsulated in this way is called a strategy."

Notice that the definition of the strategy pattern is independant of the "computational context and its execution in this context" as this is more of a way to model the aplication than to execute the modeled aplication.

The explanation also misrepresents the strategy pattern in Java by creating multiple interfaces when the pattern clearly defines only one interface for the many "strategies" of computation that will be selected and eventually injected by another pattern, into a context of execution. The very notion of the Strategy Design Pattern could be said to be averse to composition and this example does the exact opposite.

I suggest looking into Composite, Proxy and Decorator design patterns as good options of "injecting of a function into a computational context and its execution in this context".

Currying vs. partial application

Hi thma,

great project! It's important to connect the OO world and the FP world. Doing so by matching design patterns to type classes should give valuable insights.

In the Section "Functor -> Strategy" there is a comment about currying

 context :: Num a => (a -> a) -> [a] -> [a]
 context f l = map f l
  -- according to the rules of currying this can be abbreviated to:
 context = map

Currying is taking a function from (a, b) -> c to a -> b -> c, so I'm not sure that just leaving the function arguments is really currying. It is rather related to the pointfree style.

So maybe the comment should rather say "using point free style", or "in Haskell it is possible to not write the arguments".

Best,
Johannes

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.