From 74d0482ace8fd3b5ab2b310a13d4882f22c29bc6 Mon Sep 17 00:00:00 2001 From: Evan Czaplicki Date: Sat, 1 Mar 2014 13:58:02 -0500 Subject: [PATCH] Move show function to String library and get rid of Prelude library --- compiler/Metadata/Prelude.hs | 8 ++++---- libraries/Dict.elm | 3 +-- libraries/Native/String.js | 4 +++- libraries/Prelude.elm | 8 -------- libraries/String.elm | 10 +++++++++- 5 files changed, 17 insertions(+), 16 deletions(-) delete mode 100644 libraries/Prelude.elm diff --git a/compiler/Metadata/Prelude.hs b/compiler/Metadata/Prelude.hs index 7a6239b..38631db 100644 --- a/compiler/Metadata/Prelude.hs +++ b/compiler/Metadata/Prelude.hs @@ -20,12 +20,12 @@ add noPrelude (Module name exs ims decls) = Module name exs (customIms ++ ims) d Just _ -> [] prelude :: [(String, ImportMethod)] -prelude = string : text ++ map (\n -> (n, Hiding [])) modules +prelude = string ++ text ++ map (\n -> (n, Hiding [])) modules where text = map ((,) "Text") [ As "Text", Hiding ["link", "color", "height"] ] - string = ("String", As "String") - modules = [ "Basics", "Signal", "List", "Maybe", "Time", "Prelude" - , "Graphics.Element", "Color", "Graphics.Collage", "Native.Ports" ] + string = map ((,) "String") [ As "String", Importing ["show"] ] + modules = [ "Basics", "Signal", "List", "Maybe", "Time", "Color" + , "Graphics.Element", "Graphics.Collage", "Native.Ports" ] interfaces :: Bool -> IO Interfaces interfaces noPrelude = diff --git a/libraries/Dict.elm b/libraries/Dict.elm index 8b36665..55c6afb 100644 --- a/libraries/Dict.elm +++ b/libraries/Dict.elm @@ -35,7 +35,6 @@ import Basics (..) import Maybe (..) import Native.Error import List -import String import Native.Utils -- BBlack and NBlack should only be used during the deletion @@ -197,7 +196,7 @@ lessBlackTree t = case t of reportRemBug : String -> NColor -> String -> String -> a reportRemBug msg c lgot rgot = - Native.Error.raise . String.concat <| [ + Native.Error.raise <| List.concat [ "Internal red-black tree invariant violated, expected ", msg, "and got", diff --git a/libraries/Native/String.js b/libraries/Native/String.js index 1549e4e..c1c4d0e 100644 --- a/libraries/Native/String.js +++ b/libraries/Native/String.js @@ -10,6 +10,7 @@ Elm.Native.String.make = function(elm) { var Maybe = Elm.Maybe.make(elm); var JS = Elm.JavaScript.make(elm); var Utils = Elm.Native.Utils.make(elm); + var show = Elm.Native.Show.make(elm); function isEmpty(str) { return str.length === 0; @@ -243,9 +244,10 @@ Elm.Native.String.make = function(elm) { endsWith: F2(endsWith), indexes: F2(indexes), + show:show, toInt: toInt, toFloat: toFloat, toList: toList, fromList: fromList, }; -}; \ No newline at end of file +}; diff --git a/libraries/Prelude.elm b/libraries/Prelude.elm deleted file mode 100644 index 3958d2a..0000000 --- a/libraries/Prelude.elm +++ /dev/null @@ -1,8 +0,0 @@ -module Prelude where -{-| Everything that is automatically imported -} - -import Native.Show - --- Convert almost any value to its string representation. -show : a -> String -show = Native.Show.show \ No newline at end of file diff --git a/libraries/String.elm b/libraries/String.elm index e5afc97..37faf99 100644 --- a/libraries/String.elm +++ b/libraries/String.elm @@ -15,7 +15,7 @@ are enclosed in `"double quotes"`. Strings are *not* lists of characters. @docs contains, startsWith, endsWith, indexes, indices # Conversions -@docs toInt, toFloat, toList, fromList +@docs show, toInt, toFloat, toList, fromList # Formatting Cosmetic operations such as padding with extra characters or trimming whitespace. @@ -278,6 +278,14 @@ indexes = Native.String.indexes indices : String -> String -> [Int] indices = Native.String.indexes +{-| Turn any kind of value into a string. + + show 42 == "42" + show [1,2] == "[1,2]" +-} +show : a -> String +show = Native.String.show + {-| Try to convert a string into an int, failing on improperly formatted strings. toInt "123" == Just 123