Skip to content

Instantly share code, notes, and snippets.

@andrewhr
Created May 21, 2015 01:34
Show Gist options
  • Select an option

  • Save andrewhr/82b77b80365be686ff83 to your computer and use it in GitHub Desktop.

Select an option

Save andrewhr/82b77b80365be686ff83 to your computer and use it in GitHub Desktop.

Revisions

  1. andrewhr created this gist May 21, 2015.
    22 changes: 22 additions & 0 deletions failture.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    (deftype Event (U :new-release))

    (defn probability :- Float
    "Return the probability of some `Event` to occur. IRL this should be some
    real and complicated calculus instead of a simply constant"
    [event :- Event :> Float]
    0.95)

    (defn descriptive-propability
    "Describe the probability of a given `Event` to occur, for human readers."
    [event :- Event] :- String
    (match (probability event)
    1.00 "certain"
    0.00 "impossible"
    (range 0.00 0.25) "very unlikely"
    (range 0.25 0.50) "unlikely"
    (range 0.50 0.75) "likely"
    (range 0.75 1.00) "very likely"
    _ (unreachable!)))

    (defn -main []
    (println! (descriptive-propability :new-release)))