Blogging in Lisp


Feed Aggregator Page 387

Rendered on Fri, 12 Jul 2019 12:31:48 GMT  newer latest older 

Syntax Proposal : remove type aliases

via Elm - Latest posts by @Janiczek Martin Janiczek on Fri, 12 Jul 2019 09:43:37 GMT

You can hide some elm-analyse guidelines with a config file. They’re not gospel :slight_smile:

Global constants/Reader pattern

via Elm - Latest posts by @system system on Fri, 12 Jul 2019 06:00:52 GMT

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.

Looking for a mentor to build a behavioural experiments editor for psychologists

via Elm - Latest posts by @nqthqn Nate Nichols on Fri, 12 Jul 2019 05:22:31 GMT

PsychoPy was of course more geared towards writing experiments.

We had pretty good success writing a few different games in Elm. One was used in an fMRI scanner. The others online. The research group studies eating disorders.

You can see some of the code here:

The backend is unavailable so it is unlikely you will be able to get it running. The code is also pretty rough — was was very new to Elm and had help from people who wrote stylistically different.

Music composition in Elm

via Elm - Latest posts by @Lucas_Payr Lucas Payr on Fri, 12 Jul 2019 05:01:30 GMT


Yes that really should happen. Personally, I’d rather call it elm-music than elm-euterpea.

We currently use tone.js. It seems like webaudiofont is sample/waveTable based while tone.js simulates a synthesizer. I personally like having a synthesizer but on the other hand webAudioFont has Midi-In and Midi-Out. Maybe we want to join both libarays? tune.js has a Midi format. It shouldn’t be that difficult to compine both…:thinking:

Music composition in Elm

via Elm - Latest posts by @jxxcarlson James Carlson on Fri, 12 Jul 2019 02:44:36 GMT

Hi Leif,

I looked at your code. Very, very nice!! (Listened to the demo as well). I think in most respects you are farther along with an Elm version of Euterpea than am I. I’ve been working on this for a short while – it grew out of my wacky drum language project – first commit on June 27.

About a library – this is most definitely what should happen. Let’s talk some more. There is plenty to do to make a really good Elm Euterpea, and collaboration might be a good way to accomplish that. I’m interested. I think that @Lucas_Payr would be also. He’s helped me several times already.

Oh – one more point. Despite my experiments, I agree that it is desirable to stay as close to Hudak’s design as possible while writing idiomatic Elm. He has put a lot of thought into this.

PS. Here is the latest version of my test app: – not very impressive. It really only plays one voice at the moment. I’m using Tone.js as the backend.


Syntax Proposal : remove type aliases

via Elm - Latest posts by @Chadtech Chadtech on Thu, 11 Jul 2019 23:15:17 GMT

Alright. I guess using type alias to re-export an internal type, or to conceal a type within a module, like you do in your examples @xarvh @gampleman is pretty compelling. Those are good points. Thank you.

But I think thats the exact kind of example where I feel it doesnt benefit. Readers arent going to know what an ActorFunction is right away, so they have to go to the definition which is just as long as the long type signature you are avoiding. The only consequence is that readers have to look up the definition; not that the actual definition is any shorter.

Since you’ve mentioned it, while I liked using elm-analyse, I never liked that rule in particular. I love one field records because…

  • One field records have to be constructed, which means the name of the field appears at the call site of the function that uses that record. You get a name where there was no name before.
    EditView.init { index = 4 }
    --> : EditView.Model

    EditView.init 4
    --> : EditView.Model, but what was 4 anyway?
  • Its much easier to refactor from a one field record to a two field record than it is to refactor from a value to a two field record.

Techniques for debugging Parsers?

via Elm - Latest posts by @Janiczek Martin Janiczek on Thu, 11 Jul 2019 21:55:19 GMT

I learned I struggle a lot with figuring out where have my various elm/parser parsers gone wrong.

So far I probably only have two techniques:

Print the dead ends as nicely as possible
expectEqualParseResult :
    -> Result (List (P.DeadEnd ParseContext ParseProblem)) a
    -> Result (List (P.DeadEnd ParseContext ParseProblem)) a
    -> Expectation
expectEqualParseResult input expected actual =
    if actual == expected then

        case actual of
            Err deadEnds ->
                    (String.join "\n"
                            :: "===>"
                            :: "Err"
                            :: deadEndToString deadEnds

            _ ->
                actual |> Expect.equal expected

deadEndToString : P.DeadEnd ParseContext ParseProblem -> String
deadEndToString deadEnd =
        metadata =
                ++ String.fromInt (deadEnd.row - 1)
                ++ ","
                ++ String.fromInt (deadEnd.col - 1)
                ++ ") "
                ++ Debug.toString deadEnd.problem
    String.join "\n    "
            :: metadata
            :: "---- with context stack ----"
            :: contextToString deadEnd.contextStack

contextToString : { row : Int, col : Int, context : ParseContext } -> String
contextToString context =
        ++ String.fromInt (context.row - 1)
        ++ ","
        ++ String.fromInt (context.col - 1)
        ++ ") "
        ++ Debug.toString context.context
Example result
↓ ParserTest
↓ Stage.Parse.Parser.expr
↓ literal string
✗ empty


        (0,2) ExpectingDoubleQuote
        ---- with context stack ----
        (0,0) InString
        (0,0) InLiteral
        (0,0) InExpr

↓ ParserTest
↓ Stage.Parse.Parser.expr
↓ literal string
✗ one space

    " "

        (0,3) ExpectingDoubleQuote
        ---- with context stack ----
        (0,0) InString
        (0,0) InLiteral
        (0,0) InExpr

↓ ParserTest
↓ Stage.Parse.Parser.expr
↓ literal string
✗ two numbers


        (0,4) ExpectingDoubleQuote
        ---- with context stack ----
        (0,0) InString
        (0,0) InLiteral
        (0,0) InExpr

`log` parser combinator
log : String -> Parser_ a -> Parser_ a
log message parser =
    P.succeed ()
        |> P.andThen
            (\() ->
                    _ =
                        Debug.log "starting" message
                    (\source offsetBefore parseResult offsetAfter ->
                            _ =
                                Debug.log "-----------------------------------------------" message

                            _ =
                                Debug.log "source         " source

                            _ =
                                Debug.log "chomped string " (String.slice offsetBefore offsetAfter source)

                            _ =
                                Debug.log "parsed result  " parseResult
                    |= P.getSource
                    |= P.getOffset
                    |= parser
                    |= P.getOffset
Example result
starting: "many"
-----------------------------------------------: "many"
source         : "\"42\""
chomped string : "42\""
parsed result  : ['4','2','"']
starting: "many"
starting: "many"
-----------------------------------------------: "many"
source         : "\"\\\"\""
chomped string : "\\\"\""
parsed result  : ['"','"']
starting: "many"
starting: "many"

What are yours? What do you usually do when you need to debug a Parser?

Music composition in Elm

via Elm - Latest posts by @leif Leif Battermann on Thu, 11 Jul 2019 21:54:09 GMT


I’ve been interested in Euterpea for quite a while.

So I ported everything to Elm and stayed as close to the source as possible. I think it can be made more Elm idiomatic but the lib is so well designed that I didn’t want to mess around with it.

So the sequencing is solved already in the Haskell code. There is a function line that does the trick, Here is the Elm version:

line : List (Music a) -> Music a
line =
    List.foldr Seq empty

Here is the repository of the Elm version:

I just recently started this so this is still much WIP and I don’t know yet where this should go. But maybe it would be nice to create a library out of this at some point and maybe an accompanying npm package?

My first attempt was to do playback with webaudiofonts, you can see a live demo here:

I’d love to collaborate on this if someone is interested?


Quicklisp news: July 2019 Quicklisp dist update now available

via Planet Lisp by on Thu, 11 Jul 2019 20:02:00 GMT

New projects:
  • adopt — Simple, flexible, UNIX-style option parsing. — MIT
  • bike — Common Lisp .Net Core Interop — MIT
  • binpack — Rectangle packer for sprite/texture atlases — MIT
  • cl-ipfs-api2 — Bindings for the IPFS HTTP API. — GPLv3
  • cl-keycloak — Describe cl-keycloak here — GPLv3
  • cl-lzlib — lzip (LZMA) (de)compression using binding to lzlib — GPL-3
  • cl-steamworks — Generator for the low-level steamworks bindings. — zlib
  • csv — Read CSV into lists natively. Convert CSV into lists dangerously. — GNU GPL, version 3
  • datum-comments — datum #;(comments) for common lisp — Public Domain (Unlicense)
  • fiveam-asdf — Library to integrate FiveAM testing with ASDF TEST-OP and TEST-SYSTEM — Lisp LGPL
  • lastfm — Interface for the API ( — GPLv3
  • lyrics — Song lyrics with local database — GPLv3
  • method-hooks — simple qualifiable hooks defined like methods with the option to modify the dispatch method and how dispatch happens — Mozilla Public License Version 2.0
  • origin — A native Lisp graphics math library with an emphasis on performance and correctness. — MIT
  • patchwork — A spritesheet packer for games. — MIT
  • youtube — Play youtube urls with or without video using mpv — GPLv3
  • zbucium — music player with lyrics — GPLv3
Updated projects3d-matrices3d-vectorsalexandriaalso-alsaaprilarray-operationsarray-utilsatomicsaws-sign4binfixbstcari3sceplceramiccffichirpcl+sslcl-algebraic-data-typecl-allcl-anacl-cffi-gtkcl-collidercl-db3cl-decimalscl-digikar-utilitiescl-enumerationcl-environmentscl-feedparsercl-flaccl-fondcl-formscl-fusecl-fuse-meta-fscl-gamepadcl-glfw3cl-gpiocl-hamcrestcl-inotifycl-just-getopt-parsercl-k8055cl-ledgercl-mangocl-marklesscl-mixedcl-monitorscl-mpg123cl-mpicl-ntp-clientcl-openglcl-out123cl-patternscl-pngcl-rabbitcl-random-forestcl-rdkafkacl-rulescl-smtpcl-soloudcl-spidevcl-strcl-whocl-yesqlclackcleshclipcloser-mopclsscom.clearly-useful.generic-collection-interfacecommand-line-argumentsconcrete-syntax-treeconfiguration.optionscroatoancrypto-shortcutscxml-rngdata-lensdeedsdeferreddefinitionsdissectdjuladocbrowserdocumentation-utilsdoubly-linked-listdufyeazy-projecteclectorelffind-portflac-metadataflac-parserflarefloat-featuresflowforform-fiddlefxmlgendlgeneric-clglsl-toolkitgolden-utilshalftoneharmonyhelambdaphumblericlendarincf-clinkwellironcladjsownkenzolambda-fiddlelanguage-codeslasslegitlichat-ldaplichat-protocollichat-serverliblichat-tcp-clientlichat-tcp-serverlichat-ws-serverlionchatlistopialocal-timelquerymaidenmcclimmitommapmodularizemodularize-hooksmodularize-interfacesmultilang-documentationmultiposterninevehnodguinorthnumpy-file-formatosicatoverlordoxenfurtpango-markupparachuteparsleypathname-utilspetalisppipingplokamiplumpplump-bundleplump-sexpplump-texpngloadpy4clpzmqqlotqmyndqt-libsqtoolsqtools-uiquickutilquilcqvmracerrandom-stateratifyredirect-streamregular-type-expressionremote-jsreplicrpcqrtg-mathsc-extensionsscreamersealable-metaobjectsselserapeumshadowsimple-actorssimple-inferiorssimple-tasksslimeslysnoozesoftdrinksouthstaplestatic-dispatchstudio-clientstumpwmsystem-localeterrabletootertrace-dbtriviatrivial-argumentstrivial-backtracetrivial-benchmarktrivial-bit-streamstrivial-cltl2trivial-continuationtrivial-featurestrivial-indenttrivial-main-threadtrivial-mimestrivial-monitored-threadtrivial-pooled-databasetrivial-signaltrivial-thumbnailtrivial-utilitiestrivial-variable-bindingsubiquitousumbrausocketverbosevernacularwoo.

To get this update, use (ql:update-dist "quicklisp").


Localization of Elm app

via Elm - Latest posts by @Herteby Simon Herteby on Thu, 11 Jul 2019 17:43:13 GMT

Here’s another interesting solution I’ve seen to the “bucket brigade” problem (having to pass the current language to all view functions in your app)
It replaces the regular Html type with a type that’s actually a function. Then at the top level of your app you resolve it with the selected language. This way you do it all in Elm, without complicating your build step.

What do you think? Anyone tried it?

freeCodeCamp's JavaScript Calculator project built in Elm

via Elm - Latest posts by @dwayne Dwayne Crooks on Thu, 11 Jul 2019 17:18:33 GMT


Here’s the source code. And, I shared some thoughts in the README based on my experiencing building the app.

Looking for a mentor to build a behavioural experiments editor for psychologists

via Elm - Latest posts by @Yoelis Yoelis on Thu, 11 Jul 2019 14:48:05 GMT

Hi @nqthqn,

Thanks, happy to be there!

That’s very interesting. How was your experience using psychopy and elm ?

Thanks a lot for this generous offer ! I’ll send you a PM in the beginning of September so we can discuss a little bit more about this mentorship :slight_smile:

Localization of Elm app

via Elm - Latest posts by @hpate Henry on Thu, 11 Jul 2019 13:48:02 GMT

We do something similar, we have JSON files that are named like en-us.json that contain the localization data.

"welcome-message": "Welcome %s, you have %d notifications",
"plain-message": "Hello"

At build time we have a webpack plugin that turns those into Elm code like

welcomeMessage: String -> Int -> String
welcomeMessage s1 d1 =
    "Welcome " ++ s1 ++ ", you have " ++ String.fromInt d1 ++ " notifications"

plainMessage: String
plainMessage =

There are a few things I really like about that approach:

  • It works with dead code elimination, unused translations won’t show up in the optimized build
  • Plain string values get compiled away during the optimize step (meaning no function call overhead for strings like plainMessage.
  • Missing translations are a compile error

The downside is that you have to have separate builds for each language. In day to day use I like it a lot more than our previous solution of keeping a Dict String String on the Session object in our model, it becomes cumbersome to pass the session everywhere you need a translation in my opinion.

Localization of Elm app

via Elm - Latest posts by @Herteby Simon Herteby on Thu, 11 Jul 2019 12:41:45 GMT

I think the best solution depends on the size of your company, who does the writing/translation, and how many languages you want to support. We will only ever need to support 2 languages, so I think we’ll go with compile-time translations like @gampleman, but just write them directly as Elm files.

I’m thinking of having two folders like:

  • Swedish
    • Common.elm
    • Salaryfiles.elm
  • English
    • Common.elm
    • Salaryfiles.elm

And then the build script would rename one of the folders to Text and build, and then rename the other one to Text and build. If the languages don’t match, you’ll get an error at build time.
For development you could have a symlink like Text -> Swedish

Btw, all phrases wouldn’t need to be simple strings either, you could have functions like:

pluralFruit : Int -> Fruit -> String
pluralFruit count frut =
  case fruit of
    Banana ->
      String.fromInt count ++ " banan" ++ (if count == 1 then "" else "er")

Like string templates but type safe :slightly_smiling_face:

Localization of Elm app

via Elm - Latest posts by @Chadtech Chadtech on Thu, 11 Jul 2019 10:41:06 GMT

I have used ChristophP/elm-i18next a lot. It was a good experience. (Christoph, the author, was my coworker). Just from floating around Elm meet ups, I can recall two other teams that used basically the same approach as ChristophP/elm-i18next and were also happy with it.

But its not the only approach. Like @gampleman points out, there are different costs and benefits to different approaches. I have also seen an approach like this:

type Language 
    = English
    | German
    | Spanish

hello : Language -> String
hello lang =
    case lang of
        English ->

        German ->
        -- ..

The benefits as I see it are:

  • Type safety
  • Ability to change languages without reloading the app, or fetching a new set of translations

Costs I see are:

  • Either the developers have to put in every language manually or you need a complex compile-to-elm system
  • Bigger program size, since you have all the languages all the time.

Idea for a unified date/time package using extensible records

via Elm - Latest posts by @system system on Thu, 11 Jul 2019 09:21:19 GMT

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.

Why is Html a single DOM node?

via Elm - Latest posts by @roberth Robert Hensing on Thu, 11 Jul 2019 08:27:51 GMT

@Jess_Bromley, elm-ui seems to provide a really good ‘language’ to describe user interfaces.

This library is a complete alternative to HTML and CSS.

Sadly that’s too big a change for us right now, because it’s very compelling.

HTML semantics seem to embrace its “rose tree” format and always provide some meaning for the juxtaposition of siblings. elm-ui doesn’t seem to leave that meaning implicit and only defines it for elements that have the explicit purpose of combining elements, such as row. Interestingly, it does define Element.none, so Element msg seems to be a bit like Maybe (Html msg) (where Html has the usual definition).

Why is Html a single DOM node?

via Elm - Latest posts by @Jess_Bromley Jess Bromley on Thu, 11 Jul 2019 00:17:38 GMT

I think elm-ui resolves this problem by highlighting the semantic differences. Most elements can only have one child and so only take another Element msg as an argument. Those that have multiple children (and so take List (Element msg)) do so for a reason made obvious in their name, e.g. Element.row or Element.column. Not only does this make it much easier to work out which you need to hand to a given element, but what you have and what the element expects are more often than not already the right thing anyway. If you haven’t looked at it, it’s definitely worth checking out…

How to embed canvas elements into browser.elements?

via Elm - Latest posts by @system system on Wed, 10 Jul 2019 22:07:56 GMT

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.

Elm-hangman - word game

via Elm - Latest posts by @holobeat Gustav Elsner on Wed, 10 Jul 2019 21:12:52 GMT

Good observation. I have made some changes:

  • added the keyboard support for guessing the letters
  • pressing the character that has been already guessed results in failed attempt

Check on Ellie-app

 newer latest older