From ae38fe68786a7f9a4c78e43236f689a698f1aa35 Mon Sep 17 00:00:00 2001 From: Bram van den Heuvel Date: Wed, 10 Jan 2024 00:59:22 +0100 Subject: [PATCH] Introduce phantom file --- src/Internal/Config/Phantom.elm | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/Internal/Config/Phantom.elm diff --git a/src/Internal/Config/Phantom.elm b/src/Internal/Config/Phantom.elm new file mode 100644 index 0000000..7ad0489 --- /dev/null +++ b/src/Internal/Config/Phantom.elm @@ -0,0 +1,51 @@ +module Internal.Config.Phantom exposing (PString(..), PInt(..), PBool(..), PList(..)) + +{-| + + +# Phantom types + +This module contains a lot of phantom types that do not necessarily do anything, +but they force the compiler to create an error whenever something illegal is +done. + +Compiler errors may seem annoying, they can help you write good code. In a +functional programming language like Elm, the trick is to design your code in +such a way that if it compiles, it works. Phantom types can help you do so. + +The phantom types in this module help you in the following way: + +1. They can help force an compile to fault when you forget to run a function. + +2. They can help track values for security. + + +## Standard data types + +@docs PString, PInt, PBool, PList + +-} + + +{-| Opaque type that encapsulates a bool. +-} +type PBool a + = PBool Bool + + +{-| Opaque type that encapsulates an int. +-} +type PInt ph + = PInt Int + + +{-| Opaque type that encapsulates a list. +-} +type PList ph a + = PList (List a) + + +{-| Opaque type that encapsulates a string. +-} +type PString ph + = PString String