DEV Community

DrBearhands
DrBearhands

Posted on • Edited on • Originally published at drbearhands.com

2 2

Idris2+WebGL, part #14: Getting back into it

I've had a few months without progress. This project had started to get frustrating so I gravitated towards other hobbies and ideas.

Among other things, I was working on a WebGL app in JavaScript, but the explosive complexity caused by a lack of static types drove me up the walls. So many easily preventable bugs... It was a good reminder of why I want to use WebGL in Idris in the first place.

In the meanwhile, a version 0.4 of Idris was released, and with it, two features I rather like. First, do-notation now uses the >> operator as well as the >>= operator. This allows the safe discarding linear units, as >> consumes them. Where previously I had to write:

do
  () <- clearColor 0 0 0 1
  () <- clear (GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT)
Enter fullscreen mode Exit fullscreen mode

just to pattern-match / consume the linear unit value, now I can just write

do
  clearColor 0 0 0 1
  clear (GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT)
Enter fullscreen mode Exit fullscreen mode

additionally, the FFI with JavaScript has changed, so that I need far fewer conversion to and from BigInt. Nice.

Finally, I found a rather essential bit of information I was ignorant of: with linear typing comes not one, but two new functors!. This in itself wasn't groundbreaking, but it made me realize, more than I did before, that linear types require fundamentally different control structures. Were I was previously struggling to find the right type declaration for a linear Traversable typeclass, so that I could make a for function, without knowing if it iterates over linear or constant values... now I decided to simply make 2 foldM functions for lists only:

foldM : LMonad m => ((1 _ : b) -> (1 _ : a) -> m b) -> (1 _ : b) -> (1 _ : List a) -> m b
foldM' : LMonad m => ((1 _ : b) -> a -> m b) -> (1 _ : b) -> List a -> m b
Enter fullscreen mode Exit fullscreen mode

Problems gone! I can think about Traversable typeclasses after I get a better understanding of the abstract subject matter and its practical use.

I plan to focus a little less on getting as much of the WebGL spec exactly in the type system and more on making an actual app in tandem. To go for the "eat your own dog food" approach. I still want to end up with a spec that completely encompasses the documentation in the types, but I might drop or rework certain functions that just don't make a lot of sense.

Google AI Education track image

Build Apps with Google AI Studio 🧱

This track will guide you through Google AI Studio's new "Build apps with Gemini" feature, where you can turn a simple text prompt into a fully functional, deployed web application in minutes.

Read more →

Top comments (0)

Google AI Education track image

Build Apps with Google AI Studio 🧱

This track will guide you through Google AI Studio's new "Build apps with Gemini" feature, where you can turn a simple text prompt into a fully functional, deployed web application in minutes.

Read more →

👋 Kindness is contagious

Appreciate this enlightening write-up and be part of the vibrant DEV Community. Developers of every background are invited to pitch in and enrich our collective expertise.

A simple “thanks” can make someone’s day. Share your gratitude in the comments.

On DEV, knowledge-sharing lights our journey and strengthens our ties. Enjoyed the article? A kind note to the author goes a long way.

Join the community