2 ms·
That function example is not allowed in Haskell. It's pure functional throughout, not just at "function boundaries". I agree that conceptually a language can b
by jiggawatts 5y ago
That function example is not allowed in Haskell. It's pure functional throughout, not just at "function boundaries".
I agree that conceptually a language can be made where only function boundaries are required to be side-effect free, and internally "anything goes" as long as it doesn't pollute the outside world. This might be a good model for circuit design, especially if using something like an IO monad to store persistent state across clocks, such as flip-flops or registers.
However, this is not what Haskell does, at all. There are no mutation functions like "fill(x)". You have to create the buffer filled with x right from the beginning.
More importantly, in Haskell that buffer is defined with a recursion, so it looks something like: (x,(x,(x)))
Effectively it is an immutable linked list. Any modification involves either rebuilding the whole thing from scratch (recursively!) or making some highly restricted changes such as dropping the prefix and attaching a new one, such as (y,(x,(x))).
Haskell is not LISP, F#, or Clojure. It's pure and lazy, which is very rare in functional programming. It's an entirely different beast, and I don't see how any variant of it is a good fit for circuit design, which is inherently highly stateful and in-place-mutable.
- rowanG077 5y agoSuch a function is perfectly allowed and even encouraged, see here where I allocate a mutable array with undefined values and write and read from it in a pure function. Basically replicating the pseudo imperative code I have written before: https://replit.com/@RowanGoemans/QuarrelsomeUtilizedMicrokernel#Main.hs:11:10 https://replit.com/@RowanGoemans/QuarrelsomeUtilizedMicroker... Using mutable vectors like this is a must if you need to write high performance Haskell code. I have also written concrete code for magicalhippo in another branch of this thread.
- jiggawatts 5y agoThat's a clever hack that was added decades after I learned Haskell. I mean... it works, but it's not in the spirit of Haskell, which is my point. It's not impossible to write pure functional software in C. It just goes against its grain.
- rowanG077 5y agoMonadic computations are very much in the spirit of Haskell. I don't think the Haskell community view the ST monad as a hack. It's one of many tools in the box of any Haskell programmer.