<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: EstebanMarin</title>
    <description>The latest articles on DEV Community by EstebanMarin (@estebanmarin).</description>
    <link>https://dev.to/estebanmarin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1271916%2F7d2ce6bc-89d8-4f70-955a-79f0e3ad143d.png</url>
      <title>DEV Community: EstebanMarin</title>
      <link>https://dev.to/estebanmarin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/estebanmarin"/>
    <language>en</language>
    <item>
      <title>Learning Physics with Functional Programming and Haskell</title>
      <dc:creator>EstebanMarin</dc:creator>
      <pubDate>Thu, 15 May 2025 05:09:39 +0000</pubDate>
      <link>https://dev.to/estebanmarin/learning-physics-with-functional-programming-and-haskell-l1h</link>
      <guid>https://dev.to/estebanmarin/learning-physics-with-functional-programming-and-haskell-l1h</guid>
      <description>&lt;p&gt;&lt;strong&gt;TL;DR;&lt;/strong&gt; I gave a talk at &lt;a href="https://www.lambdaconf.us/speakers/esteban-marin" rel="noopener noreferrer"&gt;LambdaConf 2025&lt;/a&gt; &lt;a href="https://www.youtube.com/watch?v=Zp5D_wMi97Q&amp;amp;t=2s" rel="noopener noreferrer"&gt;Youtube&lt;/a&gt; this is a follow up post. &lt;a href="https://github.com/EstebanMarin/lpfp-lambda-conf" rel="noopener noreferrer"&gt;Haskell Files -&amp;gt; GitHub&lt;/a&gt;. I'll post the video once I get it&lt;/p&gt;

&lt;p&gt;Also, please, if you like the post and get curious, make sure to buy the book from &lt;a href="https://www.amazon.com/Learn-Physics-Functional-Programming-Hands/dp/1718501668" rel="noopener noreferrer"&gt;Scott N. Walck&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2yuadhipuj7s031jt996.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2yuadhipuj7s031jt996.png" alt=" " width="800" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This talk is about objects and arrows that point to objects. And you will see a lot of that throughout the talk&lt;/p&gt;

&lt;p&gt;Last year I learned that functional programming is a great tool to learn Physics, because it’s a great way to write math. &lt;/p&gt;

&lt;p&gt;You see, Physics is expressed in the language of Math. &lt;br&gt;
The relation of Math and code is now more present than ever. &lt;br&gt;
Therefore, applying my debugging skills as a software developer, I was able to get a deep understanding of physics whilst writing code, which was a lot of fun, and I want to share the experience with you.&lt;/p&gt;

&lt;p&gt;With this talk, I hope to explain Newton’s second law, describing the problem through types and writing math as code to help us compute functions.  This is a new perspective on learning Functional Programming and/or Physics.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8urgvi1ak0ja4qoqayb5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8urgvi1ak0ja4qoqayb5.png" alt=" " width="582" height="570"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Haskell is one of the best tools for drawing objects and arrows!!!! &lt;/p&gt;

&lt;p&gt;People do not see this as a graphical language, but I would like to show otherwise.&lt;br&gt;
We will derive our code implementation magically by taking a math equation and transcribing it letter by letter into Haskell code. &lt;/p&gt;

&lt;p&gt;But we will get types for free!! And this is mind-bending. &lt;/p&gt;

&lt;p&gt;Code will not feel like code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ihkcfuv5qhnai47mymq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ihkcfuv5qhnai47mymq.png" alt=" " width="708" height="536"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Describing our domain problem through types&lt;/p&gt;

&lt;p&gt;Here we are just writing types in Haskell&lt;/p&gt;

&lt;p&gt;We start with a wrapper over double for a Real number, I know, big assumption, but let’s carry on.&lt;/p&gt;

&lt;p&gt;We also see a function definition and each time you see an -&amp;gt; I want you to think of a normal math function.&lt;/p&gt;

&lt;p&gt;The one you would write on a piece of paper  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr0vnqjxwk75evgkyzsco.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr0vnqjxwk75evgkyzsco.png" alt=" " width="800" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Visually, the Haskell compiler is representing the following&lt;/p&gt;

&lt;p&gt;Everything encoded as a Real number: acceleration, velocity, position and time.&lt;/p&gt;

&lt;p&gt;The interesting question is: How to jump between the endpoints? &lt;/p&gt;

&lt;p&gt;How do you go from a position function to a velocity function, and even more interesting, how do you come back?&lt;/p&gt;

&lt;p&gt;The answer is arrows!! And in Haskell, that's a function.&lt;/p&gt;

&lt;p&gt;Describing the type of function in this question, we can start implementing code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F916zherub84cpsxi5qgj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F916zherub84cpsxi5qgj.png" alt=" " width="800" height="521"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Defining velocity as distance travel through time. &lt;/p&gt;

&lt;p&gt;Rewriting the definition for smalls t&lt;/p&gt;

&lt;p&gt;And limiting the delta T to cero&lt;/p&gt;

&lt;p&gt;We will arrive to the instantaneous velocity&lt;br&gt;
Once we have definition of instant velocity. &lt;/p&gt;

&lt;p&gt;We can implement derivatives in Haskell &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpcagox3d3ssb4qdvq1x6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpcagox3d3ssb4qdvq1x6.png" alt=" " width="800" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code in haskell is a one to one mapping of the function you would write on a piece of paper.&lt;/p&gt;

&lt;p&gt;This can also be python code too. &lt;/p&gt;

&lt;p&gt;The real kick comes when the Haskell compiler infers the types, which come for free!!! &lt;/p&gt;

&lt;p&gt;(first mind blow moment for me) Thinking of calculus through types&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ey1f8hrg6o4os2t3so6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ey1f8hrg6o4os2t3so6.png" alt=" " width="800" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We see that derivative is a higher order function, &lt;/p&gt;

&lt;p&gt;I never really thought about derivatives as HoF, but there you go.&lt;/p&gt;

&lt;p&gt;Higher order functions can help us glue code nicely &lt;/p&gt;

&lt;p&gt;contributing us to build a very complex model&lt;/p&gt;

&lt;p&gt;Now what we have a derivative definition. &lt;/p&gt;

&lt;p&gt;Let’s revisit the core question of our initial model&lt;/p&gt;

&lt;p&gt;How from position/time measurements can we infer the particle velocity and acceleration?&lt;/p&gt;

&lt;p&gt;That’s really the question.&lt;/p&gt;

&lt;p&gt;The Haskell implementation is straightforward and very ergonomic, using point-free notation&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmz0ij55iudys3qutsk4p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmz0ij55iudys3qutsk4p.png" alt=" " width="800" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The derivative function gives the ability to move clockwise in the model, &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F87p0zxkorjookul5in6f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F87p0zxkorjookul5in6f.png" alt=" " width="800" height="503"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this is very powerful. &lt;/p&gt;

&lt;p&gt;But, How can we reverse the movement, like going counter-clockwise?&lt;/p&gt;

&lt;p&gt;Like what’s an antiderivative?&lt;/p&gt;

&lt;p&gt;Before answering what an antiderivative is:&lt;/p&gt;

&lt;p&gt;Let’s explore an old idea idea that came even before derivatives. &lt;/p&gt;

&lt;p&gt;It’s dividing something by parts and sum them all together to get an approximation of the whole.&lt;/p&gt;

&lt;p&gt;Here we are stating that &lt;/p&gt;

&lt;p&gt;the area under the function is the bounded integral of a function between A and B&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw5ia77s7r7p52wjzxvq7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw5ia77s7r7p52wjzxvq7.png" alt=" " width="800" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using equational reasoning:&lt;/p&gt;

&lt;p&gt;Means that the bounded integral is the area under the function. &lt;/p&gt;

&lt;p&gt;The intuition I want to present here is thinking of what’s left of the equal sign as the math object we want to represent&lt;/p&gt;

&lt;p&gt;And to the right of the equal sign as the way we get there, more precisely the right side &lt;/p&gt;

&lt;p&gt;Is a computation that we will give to the computer. &lt;/p&gt;

&lt;p&gt;Lets see how calculating an area does it look in haskell&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbgvgl8q0tbknkahrlrs5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbgvgl8q0tbknkahrlrs5.png" alt=" " width="800" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's start with the sum of rectangles of height f(t) times some delta t&lt;/p&gt;

&lt;p&gt;Now we need a stream of rectangles that are evenly spaced&lt;/p&gt;

&lt;p&gt;Using the midpoint rule we are going to sample f(t) here&lt;/p&gt;

&lt;p&gt;Which, I believe is a very concise way of expressing the implementation of an integral&lt;/p&gt;

&lt;p&gt;We are summing all rectangles from a to b at a midpoint rule.&lt;/p&gt;

&lt;p&gt;Now that we have our definition of bounded integral &lt;/p&gt;

&lt;p&gt;Let’s explore the types the haskell compiler provide us&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fir9kplwo4950zqaiwc20.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fir9kplwo4950zqaiwc20.png" alt=" " width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next we see that an integral can be either Analytical like we learn in highschool, or numerical.&lt;/p&gt;

&lt;p&gt;We want to do numerical integrations, more precisely, we want the computer to handle the integration for us&lt;/p&gt;

&lt;p&gt;On top we define Numerical integrations is a Type that Takes a function to integrate lower and upper bound&lt;/p&gt;

&lt;p&gt;Returns a real number as a result&lt;/p&gt;

&lt;p&gt;Coming back to the question of how to move clockwise and counterclockwise &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7f6n2o8w0btnaoh255ci.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7f6n2o8w0btnaoh255ci.png" alt=" " width="800" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We let the geniuses enter the stage and we will take their work for face value, for now.  &lt;/p&gt;

&lt;p&gt;Newton states that: &lt;/p&gt;

&lt;p&gt;Derivatives and unbounded integrals are just part of the same. &lt;/p&gt;

&lt;p&gt;One is the inverse of the other.&lt;/p&gt;

&lt;p&gt;Derivatives and unbounded integrals are just part of the same. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcbvfko17zigngf2ew93i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcbvfko17zigngf2ew93i.png" alt=" " width="606" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mathematically, the fundamental theorem of calculus is presented as:&lt;/p&gt;

&lt;p&gt;Derivatives and Antiderivatives equate&lt;/p&gt;

&lt;p&gt;The bounded integral of f(x) in the interval a through b &lt;/p&gt;

&lt;p&gt;Equates as the Anti Derivative at b minus anti derivative at a. &lt;/p&gt;

&lt;p&gt;Revisiting the intuition of moving terms around to the right so we can give the computer to compute&lt;/p&gt;

&lt;p&gt;And the mathematical object to the left. Lets actually get the Antiderivative of any function by&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdf5vbciof23ve9ak8y41.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdf5vbciof23ve9ak8y41.png" alt=" " width="800" height="445"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Revisiting the intuition of moving terms around to the right so we can give the computer to compute&lt;/p&gt;

&lt;p&gt;And the mathematical object to the left. Lets actually get the Antiderivative of any function by&lt;/p&gt;

&lt;p&gt;The Antiderivative of F(x) is &lt;/p&gt;

&lt;p&gt;An initial value F at b plus the bounded integral of the function&lt;/p&gt;

&lt;p&gt;And we can do bounded integrals in haskell already!! NUMERICALLY!!! &lt;/p&gt;

&lt;p&gt;Writing this code in haskell, or mapping the math as code &lt;/p&gt;

&lt;p&gt;we now have a function that can anti-derivate any function&lt;/p&gt;

&lt;p&gt;Again code does not feel like code and &lt;/p&gt;

&lt;p&gt;Lets look and learn from the the types we get for free!!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgxgt9avbi34blrifapx2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgxgt9avbi34blrifapx2.png" alt=" " width="800" height="443"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The type of Anti derivative is …… surprise surprise&lt;/p&gt;

&lt;p&gt;a higher order function!!! Like derivative, takes a function returns a function&lt;/p&gt;

&lt;p&gt;And we will delegate that computation to the answer to the computer so we can numerically get a useful realtime answer &lt;/p&gt;

&lt;p&gt;This means, therefore &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftse5l0zd1m96mk2q8u8m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftse5l0zd1m96mk2q8u8m.png" alt=" " width="800" height="479"&gt;&lt;/a&gt;&lt;br&gt;
We have now a cute model in haskell that can solve any Kinematic high school physics problem.&lt;/p&gt;

&lt;p&gt;Recapping: &lt;/p&gt;

&lt;p&gt;Everything encoded as a Real number, acceleration, velocity and position. &lt;/p&gt;

&lt;p&gt;and we can go from them and back using derivatives and anti-derivates.&lt;/p&gt;

&lt;p&gt;Now lets actually play around with our code and test it in real life&lt;/p&gt;

&lt;p&gt;Imagine we go outside and let fall several objects measuring it position, time and mass. Which leads us to a function as show. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frihi4iovcf4smiefb4fa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frihi4iovcf4smiefb4fa.png" alt=" " width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Could we make predictions about velocity and acceleration???&lt;/p&gt;

&lt;p&gt;The answer is yes!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fshuonedokhjcnf0931f9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fshuonedokhjcnf0931f9.png" alt=" " width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We make a derivative of a parabola, &lt;/p&gt;

&lt;p&gt;which is a slope and that’s velocity&lt;/p&gt;

&lt;p&gt;Deriving a slope gives us ….?&lt;/p&gt;

&lt;p&gt;A constant!! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqy9byeu5fbkgvgtskibq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqy9byeu5fbkgvgtskibq.png" alt=" " width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine yourself doing this experiment/measurement for several months &lt;br&gt;
varying the mass of the object, and arriving to the same acceleration constant!!!&lt;/p&gt;

&lt;p&gt;This is another moment of Netwon’s brilliancy because the notices that the constant acceleration is part of a bigger picture&lt;/p&gt;

&lt;p&gt;Newton claims again.&lt;/p&gt;

&lt;p&gt;Force is proportional to the mass times the acceleration, &lt;br&gt;
here acceleration show as a second derivate, implying a differential equation. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F046bvf47ayf9bbmx5wp1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F046bvf47ayf9bbmx5wp1.png" alt=" " width="800" height="314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How is this new Force Object relates to our initial model? We will encode it in a Real number as the others&lt;/p&gt;

&lt;p&gt;Newton created the scientific method by dissecting problems into parts, and then compose that&lt;br&gt;
Into a more complex model.&lt;/p&gt;

&lt;p&gt;We start with a simple version of the problem how does the model behaves in constant force? &lt;/p&gt;

&lt;p&gt;Like for example a as falling apple&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpm73c22yna04t6xmn2c0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpm73c22yna04t6xmn2c0.png" alt=" " width="800" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All consistent with what we measured in the lab so this is useful.&lt;/p&gt;

&lt;p&gt;Lets get more creative with our model can make predictions of velocity and position &lt;/p&gt;

&lt;p&gt;When modeling a cyclist&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhsxojwcsrq3rcpnii4xh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhsxojwcsrq3rcpnii4xh.png" alt=" " width="650" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Describing the pedaling motion as a step function as show (Describe the step function), &lt;/p&gt;

&lt;p&gt;we want to move counterclockwise &lt;/p&gt;

&lt;p&gt;And say something about the velocity and position?&lt;/p&gt;

&lt;p&gt;Slopes should appear in the velocity gauge, and an increasing function in the position gauge &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fua6mnot7ih4sb7f01ihz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fua6mnot7ih4sb7f01ihz.png" alt=" " width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s see if we can explore more connections of the model. &lt;/p&gt;

&lt;p&gt;Like a direct arrow from Force to Velocity? What does it take to get there? What can we learn?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhqaziggjll9dz7sjl6y3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhqaziggjll9dz7sjl6y3.png" alt=" " width="688" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This arrow describes a air resistance problem&lt;/p&gt;

&lt;p&gt;normally avoided in intro physics class as requires to solve a differential equation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvtavo2s8x8dqoozw7vcn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvtavo2s8x8dqoozw7vcn.png" alt=" " width="800" height="510"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, we are going to tackle it head on because it will give us the ability to solve differential &lt;br&gt;
Equations in haskell&lt;/p&gt;

&lt;p&gt;Lets go to the whiteboard&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnl9u6wjew9i3ok93umtf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnl9u6wjew9i3ok93umtf.png" alt=" " width="780" height="558"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are going to re-write newton's second law in terms of a velocity function derivative&lt;/p&gt;

&lt;p&gt;Writing the expression in haskell is straightforward.&lt;/p&gt;

&lt;p&gt;The sum of the force function depends of velocity at v0, summing all force functions and divide by m.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvz6z1giezzjbe291jl0d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvz6z1giezzjbe291jl0d.png" alt=" " width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The main intuition here is that we will think of newton’s second law as a, wait for it:&lt;/p&gt;

&lt;p&gt;first order differential equation generator function ( what a mouth full )&lt;br&gt;
That takes a list of forces (a description of the system)&lt;/p&gt;

&lt;p&gt;That is going to be injected to a integral/solver that will &lt;/p&gt;

&lt;p&gt;arrive to a solution for velocity&lt;/p&gt;

&lt;p&gt;We are going to solve this function using the Euler method&lt;/p&gt;

&lt;p&gt;Visually the method takes an initial value calculate the slope using the next value of the function as an approximation&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1slyd938qstc7lczyap6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1slyd938qstc7lczyap6.png" alt=" " width="800" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Obviously, with each step the approximation get worst, but the intuition will prove valuable.&lt;/p&gt;

&lt;p&gt;It’s to our advantage to arrive to a solution numerically rather than analytically &lt;/p&gt;

&lt;p&gt;The Euler Method will reduce to the solution to:&lt;/p&gt;

&lt;p&gt;Velocity at T + delta T equals = initial velocity + derivative of velocity times delta T, &lt;/p&gt;

&lt;p&gt;This is what’s called a initial value problem&lt;/p&gt;

&lt;p&gt;then we will iterate over this function to get stream of solutions&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvtvowj95iigb0zg1sqv0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvtvowj95iigb0zg1sqv0.png" alt=" " width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using velocity as a state descriptor of the system&lt;/p&gt;

&lt;p&gt;Initial velocity and newton's Second Law as a predictor of that next state, &lt;/p&gt;

&lt;p&gt;We can iterate over time to see our predictions evolve&lt;/p&gt;

&lt;p&gt;Visually In our model …&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqfa3xqvma2ld2cekqp1b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqfa3xqvma2ld2cekqp1b.png" alt=" " width="800" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our model now has a new arrow that takes description of forces to velocity &lt;/p&gt;

&lt;p&gt;Lets stimulate again the system with a the same step function and using the cyclist model&lt;/p&gt;

&lt;p&gt;Now adding the air resistance to our model&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4s816recjxy13kxvu2w7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4s816recjxy13kxvu2w7.png" alt=" " width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What can we expect the velocity function look like?&lt;/p&gt;

&lt;p&gt;By playing with the area and drag constant &lt;/p&gt;

&lt;p&gt;One solution can look like a cyclist reaching terminal speed due to air resistance&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1z08r2po9ynflvf2we8t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1z08r2po9ynflvf2we8t.png" alt=" " width="800" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Other is solution expresses velocity when pedaling head wind!! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F601sn6kvru935k3mix0q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F601sn6kvru935k3mix0q.png" alt=" " width="800" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now as you can see this is a pretty cool model:&lt;/p&gt;

&lt;p&gt;that solves differential equations &lt;/p&gt;

&lt;p&gt;But can we improve it?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxctz2x7a5j8dinyfij7b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxctz2x7a5j8dinyfij7b.png" alt=" " width="800" height="535"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes we can:&lt;/p&gt;

&lt;p&gt;How about we encode not over real numbers but over vector, and vector spaces.&lt;/p&gt;

&lt;p&gt;How would that look like in Haskell?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7e1zbgqkzeiqz7b1u1w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7e1zbgqkzeiqz7b1u1w.png" alt=" " width="800" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Its a data structure that groups 3 values into one. &lt;/p&gt;

&lt;p&gt;We enrich the space with the same operations we can do with Real numbers but fitted into Vectors.&lt;/p&gt;

&lt;p&gt;For example tilda minus tilda. Takes vector A and Vector B to produce another vector thats a subtracted from b &lt;/p&gt;

&lt;p&gt;We have scalar operations&lt;/p&gt;

&lt;p&gt;Our last two: we have the dot product which takes two vectors and returns a Real number&lt;/p&gt;

&lt;p&gt;And Cross product that takes 2 vectors and returns another Vector. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs7em8kr4ojmaav4q3ycl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs7em8kr4ojmaav4q3ycl.png" alt=" " width="800" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we want to see if vectors can handle derivatives and antiderivatives as that's how we jump between functions&lt;/p&gt;

&lt;p&gt;The difference is barely noticeable in the implementation. And we are caring over the same intuition&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F21bnnjz3gf4dwt8ifwga.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F21bnnjz3gf4dwt8ifwga.png" alt=" " width="800" height="570"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We would like to abstract over all these wires and create a newton solver black box&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx4gyobsqd9cwkkgejcu4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx4gyobsqd9cwkkgejcu4.png" alt=" " width="800" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The black box that we want to have is&lt;/p&gt;

&lt;p&gt;1- given a Description of a system through the sum of Forces&lt;br&gt;
2 - And a initial particle State &lt;/p&gt;

&lt;p&gt;3 - return a position function that we can then derive to have a velocity function&lt;/p&gt;

&lt;p&gt;We are not going to implement this black box but we are going to explore the types to understand how classical physics works under the hood.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffun43nx0fesr2x0n6gr4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffun43nx0fesr2x0n6gr4.png" alt=" " width="800" height="475"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fenoa6tsilzr4adu8acbg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fenoa6tsilzr4adu8acbg.png" alt=" " width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s quickly model a constant Force and constant Mass problem in space&lt;/p&gt;

&lt;p&gt;The types will show you what’s happening and how the model predicts velocity &lt;/p&gt;

&lt;p&gt;We take a numerical method (Euler or RUNGA-KUTTA 2) &lt;br&gt;
Particle state&lt;br&gt;
A delta Particle State&lt;/p&gt;

&lt;p&gt;An initial State&lt;/p&gt;

&lt;p&gt;We get our a position function&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fekkymxbkw1nb8zrvwxek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fekkymxbkw1nb8zrvwxek.png" alt=" " width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Rearranging some of the types in the black box, we will explore relativistic and newtonian predictions to the problem&lt;/p&gt;

&lt;p&gt;Noticed how the type shows us that we are taking a one Body Force&lt;/p&gt;

&lt;p&gt;A DIFFERENTIAL EQUATION, a particle state, a delta Particle state&lt;/p&gt;

&lt;p&gt;The intuition that I want to show here that we have modularity in our code. &lt;/p&gt;

&lt;p&gt;As we are using the same Differential equation solver for both Body problems.&lt;/p&gt;

&lt;p&gt;See how Newton’s model wrongly predicts that velocity will increase without a cap&lt;/p&gt;

&lt;p&gt;Newtonian predicts particle will surpass the speed of light &lt;/p&gt;

&lt;p&gt;Whereas relativistic has an asymptote at the speed of light &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flnm1uk2koq961l0exlv4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flnm1uk2koq961l0exlv4.png" alt=" " width="800" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We just went through 500 years of math and physics in less than 30 minutes, but we were able to take this ride because functional programming is a great way to write math, and math a great tool to handle complexity and describe nature.&lt;/p&gt;

&lt;p&gt;I hope this inspires more developers to explore the side of code that is about using math and functions differential equations and math objects, rather blindingly in the next upcoming framework.&lt;/p&gt;

&lt;p&gt;Being able to explore nature through Mathematical models using differential equations and making useful predictions though computers is a skill for the future for software engineers.&lt;/p&gt;

&lt;p&gt;Thank you! &lt;/p&gt;

</description>
      <category>haskell</category>
      <category>maths</category>
      <category>physics</category>
      <category>programming</category>
    </item>
    <item>
      <title>Explain to me how to nix and Haskell properly.</title>
      <dc:creator>EstebanMarin</dc:creator>
      <pubDate>Wed, 05 Feb 2025 19:48:31 +0000</pubDate>
      <link>https://dev.to/estebanmarin/explain-to-me-how-to-nix-and-haskell-properly-52l1</link>
      <guid>https://dev.to/estebanmarin/explain-to-me-how-to-nix-and-haskell-properly-52l1</guid>
      <description>&lt;h1&gt;
  
  
  Looking for help on how to properly nix with Haskell
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; I am looking for feedback on how to properly Haskell with nix. &lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;I need to install locally Haskell, with reasonable integration with vscode (LSP as a minimun)&lt;/p&gt;

</description>
      <category>haskell</category>
      <category>nix</category>
      <category>functional</category>
    </item>
    <item>
      <title>Most Modern Software engineers are not engineers at all.</title>
      <dc:creator>EstebanMarin</dc:creator>
      <pubDate>Wed, 21 Aug 2024 12:56:03 +0000</pubDate>
      <link>https://dev.to/estebanmarin/modern-software-engineers-are-not-engineers-at-all-5db0</link>
      <guid>https://dev.to/estebanmarin/modern-software-engineers-are-not-engineers-at-all-5db0</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;They are at best artisans, at worst specialized monkeys.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; Concerning the engineering profession, do not call yourself a software engineer if you dislike/disapprove/do not know concepts like lambda calculus, category theory, or abstract algebra. Furthermore, Engineers are, by law, accountable for their work, we should ask so-called "software engineers" the same. &lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;I am a trained Electrical and Electronic Engineer. I came into engineering because I LOVED math, and lucky I got &lt;code&gt;A LOT&lt;/code&gt; of it, most of my study books looked like this. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fptqeilttdzk42mdex27f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fptqeilttdzk42mdex27f.png" alt="electrical engineering equations" width="249" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you look at a mechanical engineer book it looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxvtm9y2102y8gpcm1sre.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxvtm9y2102y8gpcm1sre.png" alt="Image description" width="800" height="497"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you look at a Chemical Engineer book, you will see something like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fplz7fuzuo25wn8tu96b8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fplz7fuzuo25wn8tu96b8.png" alt="chemical engineering equations" width="602" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What do they have in common?... Engineers write Math
&lt;/h2&gt;

&lt;p&gt;Engineers write math because it's THE ONLY TOOL AVAILABLE to understand complexity, fine-tune their intuition of the problem, explore possibilities and use that to stir their solutions. It's also the best communication tool out there and is very precise.&lt;/p&gt;

&lt;p&gt;Can anyone picture a Civil engineer saying something?:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Math is overrated! I'll just start working on the bridge and let where it takes me&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Even though it is ridiculous, with enough infinite tries and resources he will eventually construct a building &lt;a href="https://en.wikipedia.org/wiki/Infinite_monkey_theorem" rel="noopener noreferrer"&gt;see infinite monkey theorem&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;like if you put a monkey to type random keystrokes infinitely will eventually write any given text (infinite monkey theorem)&lt;/p&gt;

&lt;p&gt;And for me, that's exactly how modern software is being built. It takes less than infinite time as the monkeys we use are a little more specialized but equally problematic to work with, &lt;em&gt;&lt;strong&gt;especially the 10x.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  So what do Software Engineering Books look like and how they should look like?
&lt;/h2&gt;

&lt;p&gt;Engineers do not use all of math, math is too big for them to even need it all, but they use specialization of maths. &lt;/p&gt;

&lt;p&gt;Electrical Engineers love imaginary numbers, Laplace/Taylor transformations, and linear algebra.&lt;/p&gt;

&lt;p&gt;Chemical Engineers do stochastic processes, differential equations, statistics...&lt;/p&gt;

&lt;p&gt;Software engineers, throwing the punch line of the post away here, &lt;strong&gt;they use no math&lt;/strong&gt;. That is why their books mostly show hand-drawn pictures consisting (mostly) of boxes and lines connected with no other criteria than the one given by the author, arbitrarily. If that becomes popular enough, it becomes a sort of law everyone should predicate. &lt;/p&gt;

&lt;p&gt;Book of software should be written with math like lambda calculus, abstract algebra, functional programming, or Category theory. However, at this point, most &lt;strong&gt;"Engineers"&lt;/strong&gt; will frown upon it, arguing that Functional programming is an overkill.&lt;br&gt;
Whenever I hear a Software "Engineer" complaining that FP, Monads, or Monoid are just overkill, and that's just fancy words for elitists, and you can do everything with plain JavaScript. It's me hearing that dumb Civil engineer again. &lt;/p&gt;

&lt;h2&gt;
  
  
  ACOUNTABILITY
&lt;/h2&gt;

&lt;p&gt;Engineers in general are accountable by law for their work. This means that if they sign a blueprint with their calculations of a building, and that building collapses they are accountable for that, even going to jail if the incompetence is too much to bear. &lt;/p&gt;

&lt;p&gt;WHY ARE NOT MODERN SOFTWARE ENGINEERS HELD TO THE SAME STANDARD? They are dealing with people's lives, livelihoods, savings, weapons of war, planes, and pretty much everything...&lt;/p&gt;

&lt;p&gt;If people want the Software ENGINEER title, they should sign their work and be accountable. Once you own that type of responsibility, you start using the best tools around to do your work, like Math.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;If you dislike functional programming, please do not call yourself and software engineer. You are an artisan at best, a specialized monkey at worst. &lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>scala</category>
      <category>haskell</category>
    </item>
    <item>
      <title>What haskellers do not want you to know.</title>
      <dc:creator>EstebanMarin</dc:creator>
      <pubDate>Tue, 06 Aug 2024 19:30:14 +0000</pubDate>
      <link>https://dev.to/estebanmarin/what-haskellers-do-not-want-you-to-know-134m</link>
      <guid>https://dev.to/estebanmarin/what-haskellers-do-not-want-you-to-know-134m</guid>
      <description>&lt;h1&gt;
  
  
  The &lt;code&gt;Yin&lt;/code&gt; and &lt;code&gt;Yang&lt;/code&gt; of Functional programming
&lt;/h1&gt;

&lt;p&gt;I am for one a person who is very excited about Functional Programming and Haskell.&lt;br&gt;
Normally you will see me yaping on social media about the beauty of FP, and how it's the best thing ever invented since&lt;br&gt;
sliced bread.&lt;/p&gt;

&lt;p&gt;While functional programming offers many benefits, it also comes with its own set of challenges, much like anything else in life. Interestingly, the very features that are touted as advantages—immutability, ease of reasoning, and conciseness—can also become sources of difficulty. Thus, the dual nature of functional programming, like Yin and Yang, is revealed.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is functional programming in a nutshell
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Functional programming is a method or program construction that emphasises function and their application, rather than commands and their execution&lt;/li&gt;
&lt;li&gt;Functional programming uses simple mathematical notation that allows problems to be described clearly and concisely&lt;/li&gt;
&lt;li&gt;Functional programming has a simple mathematical basis that supports equational reasoning about the properties of programs. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(Source: Thinking functionally, Richard Bird) Chapter 1 page 1.&lt;/p&gt;

&lt;p&gt;I will not go through the weeds of each bullet point, but generally, they say that FP is based on simple sound mathematical principles that make reasoning about programs easier. &lt;/p&gt;

&lt;p&gt;I am showing 2 cases where it might not be necessarily the case. &lt;/p&gt;
&lt;h2&gt;
  
  
  The YIN and YANG
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Conciseness
&lt;/h3&gt;

&lt;p&gt;Let's take the following, program over 3 &lt;strong&gt;Natural&lt;/strong&gt; numbers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// [2,3,4]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Many people might think that this code translates to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;result&lt;/span&gt;
&lt;span class="c1"&gt;// [2,3,4]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And they would be missing half the story, as this is only a partial implementation. &lt;/p&gt;

&lt;p&gt;Great we took 6 lines and converted them into 1, so is this is what we solving? &lt;/p&gt;

&lt;p&gt;The conciseness of the &lt;code&gt;[1,2,3].map(x =&amp;gt; x+1)&lt;/code&gt; is not about fewer characters, rather it hides from us several mathematical principles that will send us down a deep rabbit hole, (PLEASE BE AWARE I WILL BE USING scary words for a while)&lt;/p&gt;

&lt;p&gt;What this code is saying is that we will be mapping over a data structure (natural numbers, that will need to be encoded in the language) that has properties of Functor and probably monad. Under the hood we would have something like this in Haskell, hidden by the standard library.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- We NEED to encode the definition of numbers into the lang&lt;/span&gt;
&lt;span class="kr"&gt;data&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Zero&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kt"&gt;Succ&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt;
&lt;span class="c1"&gt;-- equality type-class we need this in order to compare numbers&lt;/span&gt;
&lt;span class="kr"&gt;instance&lt;/span&gt; &lt;span class="kt"&gt;Eq&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt; &lt;span class="kr"&gt;where&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Bool&lt;/span&gt;
&lt;span class="c1"&gt;-- we need this in order to print results&lt;/span&gt;
&lt;span class="kr"&gt;instance&lt;/span&gt; &lt;span class="kt"&gt;Show&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt; &lt;span class="kr"&gt;where&lt;/span&gt;
  &lt;span class="n"&gt;show&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;
&lt;span class="c1"&gt;-- provide binary functions we need this to tell the computer how to operate with numbers&lt;/span&gt;
&lt;span class="kr"&gt;instance&lt;/span&gt; &lt;span class="kt"&gt;Num&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt; &lt;span class="kr"&gt;where&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt;
  &lt;span class="n"&gt;abs&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Nat&lt;/span&gt;
  &lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="c1"&gt;-- and finally after we can map over our natural numbers&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Haskell hides this from you by providing utility data types such as &lt;code&gt;Num&lt;/code&gt; &lt;code&gt;Integer&lt;/code&gt; and their respective &lt;br&gt;
instances of &lt;code&gt;Eq, Semigroup, Monoid, Monad...&lt;/code&gt; and so on.&lt;br&gt;
But there you go, it's concise mathematically speaking, but at the end, you are writing more lines of code. &lt;/p&gt;
&lt;h3&gt;
  
  
  Immutability
&lt;/h3&gt;

&lt;p&gt;Probably the focal point of any OOP vs FP debate. Many FP elitists will look with disgust at any code that reassigns variable values, arguing that the state breaks the equational reasoning of programs. Where OOP pragmatics argue about the inherent performance. Both sides are right. I'll start by showing a beautiful canonical example of an FP function. Where laziness, recursive scheme and conciseness shine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Fibonacci&lt;/span&gt;
&lt;span class="n"&gt;fib&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;
&lt;span class="n"&gt;fib&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="n"&gt;fib&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;fib&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fib&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;fib&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At a glance, we have described easily how to create fib numbers, but it's a terribly inefficient function, as it takes exponential time to evaluate. By not getting into details we can improve the time performance of this function, by using  &lt;code&gt;Tupling&lt;/code&gt; technique of parameters (Chapter 7.6 Thinking Functionally, Bird.).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="n"&gt;fib&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt; 
&lt;span class="n"&gt;fib&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fst&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fib2&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fib2&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fib2&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kr"&gt;where&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fib2&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Evaluating fib now takes linear time, but the space involved is not constant (even ignoring the fact that arbitrarily large integers cannot be stored in constant space)&lt;/p&gt;

&lt;p&gt;In order to constrain the space of our solution we will introduce the ST monad and the strict operator ($!). (See Chapter 10.4 Thinking functionally. Bird) like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="n"&gt;fibST&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;ST&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="kt"&gt;Integer&lt;/span&gt;
&lt;span class="n"&gt;fibST&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kr"&gt;do&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;newSTRef&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
               &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;newSTRef&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
               &lt;span class="n"&gt;repeatFor&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;
                &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kr"&gt;do&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;readSTRef&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                     &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;readSTRef&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                  &lt;span class="n"&gt;writeSTRef&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                  &lt;span class="n"&gt;writeSTRef&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;$!&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="n"&gt;readSTRef&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
              &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;-- we need however to run the ST monad to get a proper value&lt;/span&gt;
&lt;span class="n"&gt;runST&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;forall&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="kt"&gt;ST&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;
&lt;span class="c1"&gt;-- Then we can finally have an efficient Fibonacci function that looks like&lt;/span&gt;
&lt;span class="n"&gt;fib&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Integer&lt;/span&gt;
&lt;span class="n"&gt;fib&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;runST&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fibST&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I do not know about you, but I found this significantly harder to digest.&lt;/p&gt;

&lt;p&gt;On the other hand, we can make a one-to-one translation of the Haskell code above in &lt;code&gt;python&lt;/code&gt; as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fib&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What this is telling us is that immutability is not only making our code more efficient but also easier to understand! &lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;As much as I love functional programming and using maths. Going full-on math principles can make things easy to reason but hard to implement, but having an easy implementation can lead problems reasoning &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
