Skip to content

Instantly share code, notes, and snippets.

View marick's full-sized avatar

Brian Marick marick

View GitHub Profile

TL;DR: given a functional-reference/optics library, should you be able to say "set the endpoint of this path to X, creating empty elements along the way as necessary"?


Scala and Elm have a lens implementation libraries (Scala, Elm). They add an Optional to the canonical Lens/Prism/Iso types. It's useful for dictionaries/maps/hashes. I think it corresponds roughly to Haskell/Lens's Lens.At. I have a question about the behavior of Elm's version that seems Not What You'd Want, but can't interpret the Haskell or Scala versions well enough to determine an answer from them.

The issue is composing two Optional values together. Suppose we have two Optionals that focus on particular keys in a dictionary:

  • top is an Optional tha

Types and tests in functional programming - a workshop

Edinburgh Scotland, [[[date]]]

An interesting thing about types and tests is that they have a long history of programmers embracing them reluctantly (at best). But in this century they've both become respectable -- even trendy in some circles. One difference from the old days is that proponents of both emphasize a claim that their tool is useful in design, not just in checking implementations.

This workshop assumes that claim is true enough. That is, despite all the other virtues of types and tests, we believe their value for design is worth exploring and amplifying.

However: types and tests come from radically different traditions. To a considerable extent, their communities don't talk to each other. That's a problem, because it makes it easy to see types and tests as antagonistic approaches to design. Positions could harden -- perhaps have hardened -- before there's been serious work to discover and articulate how they could be *complemen

-- To make things interesting, I decided to assume a 32-bit machine.
-- Because invalid 32-bit numbers don't lie on nice boundaries, you
-- have to be careful about doing validity checks before multiplying.
-- That is, you can't calculate out a value of 2147483648 and then
-- check if that's bigger than the 32-bit boundary (2147483647) because
-- on a 32-bit machine, the value you'd be checking would be way negative.
toInt "1" => 1
toInt "-1" => -1

What the book covers

The book will begin by teaching the ideas behind the Elm programming language. Elm is one of the breed of languages that compiles down to Javascript. It's also--as far as I know--the friendliest of the static FP languages. Its error messages are superb. Its documentation is good and errs on the side of plain language over jargon. Its emphasis is on the beginner, and the features it provides are well-chosen for that audience. Its command-line interface (the "repl"[^repl]) doesn't present you with

type alias FormCommon more =
{ more
| id : Id
, sortKey : String -- Distinct from name so that changing the name
-- doesn't cause list entries to change position
, effectiveDate : DateHolder
, intendedVersion : Int
, species : Namelike
, name : Css.FormValue Namelike
, tags : List Namelike
{-! If there is an original animal to work with, partially apply the
given function to that animal. The given function is expected to
transform some value with that function. If there is no animal,
`identity` is used.
Typically used to make transformations of Model that mean nothing
if there's no original animal. (Very likely an "impossible" case.)
model |> Form.givenOriginalAnimal form upsertAnimal |> noCmd
-}
update : FormOperation -> Form -> Model -> (Model, Cmd Msg)
update op form model =
case op of
CancelEdits ->
model |> Form.givenOriginalAnimal form upsertAnimal |> noCmd
@marick
marick / maybe.elm
Last active February 21, 2017 22:50
type alias Form =
{ -- ...
, originalAnimal : Maybe Animal
}
type alias Form =
{ id : Id
, sortKey : String -- Distinct from name so that changing the name
-- doesn't cause list entries to change position
, effectiveDate : DateHolder
, intendedVersion : Int
, species : Namelike
, name : Css.FormValue Namelike
, tags : List Namelike
, tentativeTag : String
--- THIS?
type Format
= Compact
| Expanded
| Editable Form
type alias DisplayedAnimal =
{ id : Id