I’m very excited to see the elm/bytes
repository which was made public just several hours ago by Evan.
Please read the README first, before you read the rest I’m going to write. It describes what this library is for and what it is not for.
A use case
So, I’d like to answer the following question written at the bottom of the readme.
If you have a concrete scenario in which you want to interpret bytes as densely packed arrays of integers or floats, please describe it on https://discourse.elm-lang.org/ in a friendly and high-level way. What is the project about? What do densely packed arrays do for that project? Is it about perf? What kind of algorithms are you using? Etc.
I have a very concrete use case. It is about the MIDI data format.
MIDI stands for Musical Instruments Digital Interface. It is (1) a binary protocol for transfering signals between instruments and other devices, and also (2) a binary file format to record musical information like sequence of notes, tones, tempo, etc. I think these data is not necessarily a binary, but it is already used widely and I don’t know any alternative that have a text format.
To make nice music apps, we need to read and write MIDI.
- Read MIDI file (SMF) that is uploaded by user, and show the data
- Output a new MIDI file after some edition
- Realtime playing / recording via Web MIDI
All of these need decoders and encoders for bytes.
Example
For an example, here is a MIDI (+MP3) player I made.
This is written in Elm 0.18 and uses some native code to decode MIDI. I was surprised that this app can also be embedded in tweets. So I can say “hey, this is an app written in Elm!” but sadly it requires some hacky way for now.
If you are interested in this app: my homepage
Other use cases?
I don’t know if there are any other variable use cases. I agree with the last statement in readme. Mutating large binary data seems hard in Elm and needs a lot of investigation to make a decision. Instead, it should be eadier to get some metadata from binary data, like size of images, length of audio, etc.
Anyway, I think this is a good chance to collect all possible use cases we have. Any ideas?
Note: Things like file upload (which many folks want) is also discussed in other thread: Binary and file handling in Elm - #7 by norpan