Somebody on reddit asked for a nice way of doing wizards functionally.
At least theoretically you can combine free applicatives with free monads to get a branching wizard.
Let's see how.
Let's start with how to define a form element.
{-# LANGUAGE DeriveFunctor #-} | |
{-# LANGUAGE TupleSections #-} | |
{-# LANGUAGE LambdaCase #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE RecordWildCards #-} | |
{-# LANGUAGE NamedFieldPuns #-} | |
module Main where | |
import Lucid.Base |
I hereby claim:
To claim this, I am signing this object:
{-# LANGUAGE Arrows #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE RecordWildCards #-} | |
{-# LANGUAGE TupleSections #-} | |
import Control.Applicative ((<|>)) | |
import Control.Arrow | |
import Control.Category | |
import Control.Monad (unless) | |
import Data.Maybe (fromJust) |
import Data.Map (Map) | |
import qualified Data.Map as M | |
import Data.Monoid | |
import Data.List (find, sortBy) | |
import Data.Maybe (fromMaybe) | |
import Data.Text.Lazy (Text) | |
import qualified Data.Text.Lazy as T | |
import qualified Data.Text.Lazy.IO as TI | |
import Data.Function | |
import Data.Char |
(ns topological.core) | |
(def testlist | |
[{:depends #{2} :provides 3} | |
{:depends #{2} :provides 1} | |
{:depends #{} :provides 2} | |
{:depends #{1} :provides 4} | |
]) | |
(defn free-nodes [xs] |
var Node = function(idx, x,y) { | |
this.idx = idx; | |
this.xvel = 0; | |
this.yvel = 0; | |
this.xforce = 0; | |
this.yforce = 0; | |
this.x = x; | |
this.y = y; | |
this.dampen = 0.85; | |
this.color = 'rgb(' + (Math.floor(Math.random() * 255)) + ',' + (Math.floor(Math.random() * 255)) + ',' + (Math.floor(Math.random() * 255)) + ')'; |
{-# Language GeneralizedNewtypeDeriving #-} | |
{-# Language OverloadedStrings #-} | |
import Data.Monoid | |
import Text.Blaze.Html.Renderer.Text | |
import qualified Text.Blaze.Html5 as H | |
import qualified Text.Blaze.Html5.Attributes as A | |
import Text.Blaze.Html ((!), Html) | |
import Control.Monad.Writer | |
import Control.Monad.Identity |
#!/bin/bash | |
start=$1 | |
now=$(date +%s) | |
remaining=$(($start - ($(date +%s) - $now))) | |
while [ $remaining -gt 0 ]; do | |
echo -ne "\r\033[K$remaining" | |
sleep 1; |