GithubHelp home page GithubHelp logo

davidelettieri / syb-csharp Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 32 KB

Implementing "scrap your boilerplate" pattern for c#

License: GNU General Public License v3.0

C# 100.00%
csharp scrap-your-boilerplate

syb-csharp's Introduction

syb-csharp

I'm trying to implement in C# the "Scrap your boilerplate" [SYB] approach from Haskell

I'm not sure this is possible to achieve and there is a rather long article doing the same thing for C++ so it might be to hard to do.

The SYB approach is meant to avoid to write repetitive code when dealing with complex data structures. The classical Paradise example as found in the cited article is roughly this scenario: There is a company with departments, subunits, manager and peoples and we want to rise the salary of each person.

Most of the code for solving this problem is about traversing the data structure representing the company while the actual "solving the problem" code is just a multiplication. They propose to split the problem in three parts:

  • Writing the actual code to solve the problem, this is manual and specific to the task at hand.
  • Generate automatically some functions to traverse the data structure. This is the GMapT function that I wrote by hand but that could possibly be automated using roslyn.
  • Write only once a library to support everything.

I have a working example with some shortcomings: a. I wrote all the code by hand, including the part that should be automatically generated. b. I wrote just one combinator

Most of the work is done in two generic classes MkT and EveryWhere, this approach follows the C++ article if I understood it correctly:

  • MkT takes a Func<T,T> and allows to compute the function to any U even if U != T, in this case it just returns the argument value
  • EveryWhere is the class that contains the recursion logic

Next steps:

  1. Write more combinators
  2. Write a roslyn refactor to automatically generate the GMap method
  3. Try to find a way to remove the runtime cast inside the Apply method of MkT class

About 2, I wrote a simple refactor that allows to generate correctly the GMapT method in some cases but it's missing checks and IEnumerable parameters

syb-csharp's People

Contributors

davidelettieri 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.