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

Presto @ Functional Conf 2017

1e238df38f78362ce6da2f4679e5ba39?s=47 Vimal Kumar
November 18, 2017

Presto @ Functional Conf 2017

Lessons learned building an App development platform using PureScript


Vimal Kumar

November 18, 2017


  1. Presto A Mobile App Maker Built with PureScript Lessons building,.

  2. • Built large scale systems at Juspay, Amazon, Trilogy serving

    millions of users • A convert to PureScript from Clojure / JavaScript • Passionate about building Creation tools Hello! I’m Vimal Kumar, CEO of Juspay
  3. Why do serious Apps take months to develop and millions

    of $$ to maintain PROBLEM Incidental Complexity is killing productivity!
  4. Why are Apps Hard? Event Driven Programming model complicates transactional

    apps • No clarity of flow of control - too many jumps • UX Flows are not composable
  5. Why are Apps hard? Frameworks focus on Getting started quick;

    Not on fundamentals to Control complexity • Complexity of serious apps is exponentially increasing. • Need a strong theory like Functional Programming / Category theory with extreme focus on composition. • Hard theories need years of investment to get practical advantage.
  6. Why are Apps hard? Fragmented Architecture, Need Unification • Frontend,

    Backend, Persistence, External service integration, Analytics, Business Logic, Infrastructure. • All are handled in different ways. They can be unified with a few simple building blocks.
  7. We Need to remove the Incidental Complexity and enable Freshers/PMs

    build apps with 10x less time and effort It shouldn’t be this way!
  8. How? • PureScript - Pure FP & Types • Free-Monadic

    DSL ◦ UX as Conversations ◦ Business Flows as Goal Trees ◦ PureScript Aff continuation monad • Unify. UI | Flows | Data - Only 3 Blocks
  9. DSL - as UX Conversations User System App Welcome Tell

    Ask Ask-Options Ask-Search Ask-Confirm Thank Delight Suggest Cross Sell Notify Fetch Detect Search Commit Track SetTimer Etc.. App The App Weaves a. Conversation between User & System towards a Goal Goal
  10. DSL - Composable Goal Trees • Composable Goals! • Understandable

    to non-tech - Designers, Product Managers Introduce Verify Mobile Create VPA Goal: BHIM Onboarding UI: Step 1 Help UI: Step 2 Help UI: Success OR Verify Mobile With OTP Verify Mobile Sending SMS API: Trigger OTP Poll SMS Inbox for OTP More steps Tree extends here… Local API: Send SMS Code Poll Server for SMS Code UI: Success More steps Tree extends here… More steps Tree extends here… UI: Welcome UI: Ask Mobile
  11. Welcome Dilip to the app Ask to pay the DTH

    bill (why not give some incentive!) > Ask to choose DTH Operator. If a lot, let him search > Ask for his Customer ID. Show HELP on where to find the Customer ID > Fetch his Customer Name and latest due bill amount :: LOAD > Show the bill details and Ask to pay SubFlow Collect_UPI_MPIN Commit the payment and Show confirmation status. Cross Sell Ask if he’d like to set up Auto-deduct OR Payment reminder for future bills > Thank Dilip. DSL - Readable as a Narrative
  12. DSL Code - Example 1 dthAppFlow :: User -> Flow

    Unit dthAppFlow user = showUI $ Info.Welcome user >>= fetch Api.DTHOperators >>= showUI List.DTHOperator >>= untilSuccessful $ showUI Form.CustomerId >>= fetch CustomerName >>= fetch Api.LastBill >>= showUI Info.BillDetails >>= captureUpiPinFlow >>= commit Api.UpiTransaction >>= showUI $ CrossSell.PaymentOptions [AutoDeduct, PaymentReminder] >>= autoDeductFlow <|> reminderFlow >>= showUI Info.ThankYou
  13. DSL Code - Example 2

  14. PureScript - Pure FP • Composition, State Management, Conciseness and

    Clarity • CPS (Continuation passing style) for the DSL Goal Trees • Choice of PureScript - Best of Haskell and JavaScript. • Category Theory - Functors / Monads / Applicatives
  15. Just 3 Building Blocks - Unify • UI Structure -

    Visual Components like React • Goal Tree - Flows as Pure Functions ◦ Represents the entire business logic ◦ Unified Backend and Frontend • Data as Types ◦ Single set of types for Frontend, Backend, UI, Storage ◦ Types mapped to DB data model

    ClojureScript Haskell Like + Strong FP - Focus on Purity, Composition, Conciseness. + Types - Few errors, Easy refactoring JS Integration + Solid and easy JS FFI + JS Code Small & Reliable - New and evolving + Implements all Haskell’s features and access to most Haskell Libraries. - Large size JS and not so reliable runtime + Is a Lisp! + Strong Developer community + Proven runtime - Lacks Types - Lacks strong math / category theory foundation of Haskell CPS (Continuation Passing) Elm Architecture / Redux Pure FRP Maps directly to UX flows / flows as conversion funnel. Global state complicates transactional flows vs CPS manages local state in stack More general than CPS but complicates UX flows. Presto will add FRP support in future
  17. Challenges - Steep Learning Curve Mitigation - Fast track Training

    to build confidence - Zero till Monads in 1 hour! - Simple DSL - Get started making apps without deep FP knowledge. - Systematic learning track for FP techniques (Juspay University)
  18. Challenges - Types - Type errors: Type errors can be

    hard to debug sometime taking several hours of developer time. - Decrease Spontaneity: Too much focus on correctness during the process of creation & necessity to pre-think the big picture, can be a hurdle while trying to create spontaneously. Mitigation - Forcing explicit type annotations during declarations make type errors easy to debug. - A month of training developers, improve their debugging skills and spontaneity. - Move to FreeM DSL hides the scary types from general users
  19. Big Benefits - We estimate 10x • Big Change in

    Dev Culture! It has kindled a burning desire among devs to write concise, composable, reusable code. Scale a fresher team without need for traditional Architects. There is a big reduction in stackoverflow usage! • Purity, Types, Composability, FreeM DSL ◦ Dev Speed - Unification/Reuse have drastically improved development speed. ◦ Reliability - Almost Nil bugs with Types ◦ Refactoring - High confidence to try new ideas ◦ Enabling PMs - Concise DSL code has enabled PMs to review code or write pseudocode. • PureScript - JS Interop, Small Compiled JS - small app size
  20. Apps in Production UPI SDK for top Apps Juspay Safe

    Potential for 100M+ users Other Apps: - Juspay Fuel: UPI for Petroleum - BHIM’s new features - Diksha: Teacher edu. Govt. App - Various internal ops tools@Juspay
  21. Next Steps School of Functional Programming

  22. Presto - Roadmap • Visual Programming - Sketch Plugin, Flow

    editor, Type editor • 1-Week Apps | 1-Day mini-apps • Auto API Type Creator & Quick Check • ORM + API - ~GraphQL • Custom Type Errors in PureScript compiler • Web IDE and Remote Collaboration tools • Tools to Semi-Automate JS to PS migration
  23. Presto Roadmap - Reactive system What if entire systems (clients,

    servers, storage, apis etc) are abstracted out as a Reactive system that is composed of functions! CHAT History Format Screen User1 Input User2 Input Formatted Screen Output User Id
  24. Thank you presto@juspay.in If you are interested in contributing, please

    contact us