Skip to content

Instantly share code, notes, and snippets.

View Chadtech's full-sized avatar

Chadtech Chadtech

  • SuperFocus.ai
  • Pennsylvania
View GitHub Profile
logDecode : String -> Decoder a -> Decoder a
logDecode tag decoder =
Decode.value
|> Decode.andThen (logDecodeHelper tag decoder)
logDecodeHelper : String -> Decoder -> Decode.Value -> Decoder a
logDecodeHelper tag decoder json =
let
_ =

Only have one outgoing port, and only one incoming port

If you have many ports, they could be all over your project, and therefore hard to manage and easy for forget about. Keep track of all of them by representing your outgoing ports in a union type like..

type JsMsg
    = Download
    | Login Login.Payload
    | Logout
    | Track Tracking.Payload
module Data.Thing
exposing
( Thing
, decoder
, encoder
)
import Json.Encode as Encode exposing (Value)
import Json.Decode as Decode exposing (Decoder)

Chadtech Elm Style Guide

Im one of the few lucky enough to write Elm at work. I write Elm in the evening and on the week ends too, so I am kind of Elm 24/7 nowadays. Naturally Ive developed patterns and techniques to my code, that have been invaluable to maximizing my productivity as a web developer. I will share those techniques below.

But before that, let me say that Im obviously not the first person to write up an Elm style guide. There are other style guides out there, and I would say Im in at least 90% agreement with them. Just repeating what other people have already said about writing good Elm code wouldnt add much, so I have listed techniques that dont seem to be already widespread. Also, they are listed in order of how unusual they are, with the most unusual on top. I would love a discussion about good technique, and I would love to improve, so I invite you to criticize me on anything in this document.

Never use anonymous functions

Every time you write an anonymous function, you forgo writin

Super Preliminary Elm - Web Assembly Research

Back in December 2017, I started working on something I called Elmish-Wasm, which was just an experimental repo to compile something Elm-like to Wasm. I made some progress, but the helpful people I talked and I came to the conclusion that most of what I had so far (Haskell and Regex to interpret .elm files into rudimentary wasm) was something the Elm compiler and the Elm AST already did. Writing that code was a lot of fun, but maybe not the most valuable way to explore Elm and WebAssembly. Before jumping back into this project I would like to record the important facts and questions related to compiling Elm to Wasm.

What is Wasm?

A lot of people talk about Web Assembly as if its C++ that runs in the browser. Thats not the case. This belief must come from that fact that C can currently compile to web assembly. Wasm is human-unreadable bytecode. There is a human-readable version of wasm, called wat. It looks like this..

;; A function that adds two numbe
<style>
.header {
position: fixed;
height: 12px
left: 0px;
top: 0px;
width: 100%;
}
.table {

In the last year I have gotten hyped up about predictions. Why? heres a few reasons:

  • Statistics is fun. Rationality and cognition are fun topics.
  • It exercises self awareness. We all have beliefs about the world around us. How often do we deliberately test the accuracy of our beliefs? If you dont test yourself, how do you know your beliefs arent far off the mark? If your beliefs are really off the mark, is that going to work out well for you?
  • It exercises objectivity. We all feel certainty some of the time about some of the things. If you feel really certain, is that 70%? Is it 90%? 20 points is a big difference! If you can reliably put your certainty into a number, then all the powers of math are at your disposal.
  • Seems like being able to reliably predict useful things would be a pretty good ability to have, so its probably worth practicing.

To self improve, I am doing two sorts of predictions.

Calibration Predictions

Intro
- Elm isnt a frame work
- Its ML syntax
- Its compiled
- Heres what a function is
- Here is what currying is
- Give a JS function one param, its broken, give an Elm function one param, its a totally new function
- Heres what a union type is
- Heres the architecture
module Main exposing (..)
import Server
import Res exposing (Res)
{-|
Server.program :
{ config : config
, respond : req -> Res payload
, encode : config -> payload -> Value
module Page.Register
exposing
( Model
, Msg(..)
, Problem(..)
, css
, init
, update
, view
)