TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Functional vs. Data-Driven Development: A Case-Study in Clojure and OCaml

6 pointsby gopiandcode2 months ago

1 comment

artikae2 months ago
assoc-in reminds me a lot of lenses in Haskell. I figure you could probably implement something like it using them. This is what I came up with:<p><pre><code> import Control.Lens baseLens --&gt; nextIndex = baseLens . ix nextIndex assocIn structure keyLens newValue = set keyLens newValue structure </code></pre> It works like so:<p><pre><code> setTo256 structure = assocIn structure (ix 0 --&gt; 0 --&gt; 0) 256 -- setTo256 [[[1]], [[2]]] returns [[[256]], [[2]]]</code></pre>