1. 7
  1.  

  2. 3

    Linear types were merged into GHC in June. I posted this article instead because it has the more exhaustive explanation and examples of the two.

    As a newcomer to Haskell and, to a certain extent, typed functional programming in general, I’m curious to know what applications this might have. Could it, for example, make working with graphics data (e.g. vertex buffers) in a functional context more practical by circumventing the usual GC hiccups?

    1. 1

      What are the ‘usual’ GC hiccups? Do you have a code example?

      1. 3

        I should start off by saying that I’m speaking from the admittedly limited perspective of realtime graphics on the web. I appreciate that there is a much wider world of graphics programming and that most of it happens in languages other than JavaScript. With that out of the way, I can think of a few examples:

        I also encounter this myself in my day job, which involves a fair amount of WebGL. The code is proprietary, but the concept is not: Heavy callback functions in an event loop result in significant garbage collection events, which, in turn drop frames or “jank”. This is a complaint I’ve heard from people who work on graphics full time about graphics programming in JavaScript (although I suspect they really mean most garbage collected languages).

        Going a step further, a lot of the really interesting graphics programming happens at the shader level, but shading languages such as GLSL manage memory very differently from garbage collected ones, i.e., pretty much statically. Thinking about deterministic memory allocation in a functional language, I wonder if linear types might enable a subset of functional programming languages to be compiled to shader code. Futhark seems close, but though intended to run on the GPU, is not intended for graphics.

        1. 3

          Thanks for your answer.

          I don’t know what you mean when you say “a subset of functional programming languages”, but there is sheaf/fir which is an EDSL that compiles to Vulkan.