Skip to content

Instantly share code, notes, and snippets.

View z5h's full-sized avatar
🕳️

Mark Bolusmjak z5h

🕳️
View GitHub Profile
@z5h
z5h / example.pl
Created December 6, 2023 06:00
"Monte-Carlo amb" in Prolog, proof of concept
amb_example(BestGuess) :-
run_with_monte_carlo_amb(1000,
( amb(BestGuess, [2,3,4,5,6,7,8,9,10,11,12]),
guess_the_dice_total(BestGuess)
)).
guess_the_dice_total(Total) :-
random_member(Dice1, [1,2,3,4,5,6]),
random_member(Dice2, [1,2,3,4,5,6]),
(Total =\= Dice1 + Dice2 -> amb(fail); true).
@z5h
z5h / Kernel.elm
Created May 8, 2023 14:35
Updated microKanren Kernel
-- modified version of https://package.elm-lang.org/packages/dvberkel/microkanren/latest/
-- fixing a bug, and adding reification, some practical features, and an example logic problem
module MicroKanren.Kernel exposing
( Goal, State, Stream(..), Term(..), Var
, callFresh, conjoin, disjoin
, emptyState, unit
, walk
, Substitutions, fish, l, pull, unify, v
)
@z5h
z5h / Example.elm
Last active November 23, 2020 13:10
Elm focusout focusin
import Browser.Dom
import Element exposing (Element)
import Element.Background as Background
import Element.Border as Border
import Element.Font as Font
import Element.Input as Input
import Html
import Html.Attributes
import Html.Events
import Json.Decode as Decode
@z5h
z5h / Main.elm
Created February 1, 2020 16:27
transition animations
module Main exposing (..)
import Browser
import Html exposing (Html, button, div, span, text)
import Html.Attributes exposing (style)
import Html.Events exposing (onClick)
import Timeline exposing (Timeline)
module Base.ListSet exposing
( Set
, diff
, empty
, filter
, foldl
, foldr
, fromList
, group
, insert
@z5h
z5h / Example.elm
Last active December 20, 2018 14:08
autofocus in Elm that actually works
input [
focus (item.id) (RequiresFocus_ Nothing)
else
none
]
import Stopwatch
import Html exposing (..)
import Html.App as App
import Html.Attributes exposing (..)
import Html.Events exposing (..)
main: Program Never
main =
App.program
{ init = init
module TimeApp ( start, Config, App ) where
{-| This module helps you start your application in a typical Elm workflow.
It assumes you are following [the Elm Architecture][arch] and using
[elm-effects][]. From there it will wire everything up for you!
**Be sure to [read the Elm Architecture tutorial][arch] to learn how this all
works!**
[arch]: https://github.com/evancz/elm-architecture-tutorial
[elm-effects]: http://package.elm-lang.org/packages/evancz/elm-effects/latest
@z5h
z5h / Swap.elm
Created July 24, 2015 17:23
Elm rendering focus loss
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
type Action
= NoOp
| EditEntry Entry String
type alias Entry =