From f1af3b5b0a7017c9b5f4c838f95aef578cd883bf Mon Sep 17 00:00:00 2001 From: Justin Blake Date: Tue, 17 Dec 2024 17:31:35 -0500 Subject: [PATCH 1/5] Add code samples to homepage --- src/Page/Index.elm | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/Page/Index.elm b/src/Page/Index.elm index ba3b04b..3494dcb 100644 --- a/src/Page/Index.elm +++ b/src/Page/Index.elm @@ -98,5 +98,61 @@ view _ _ _ = , Html.p [] [ Html.text "Gren produces small JavaScript files, and runs surprisingly fast. Applications written in Gren can be both smaller and faster than your average React-based application." ] ] + , Html.article + [] + [ Html.h3 [] + [ Html.text "Runs Anywhere" ] + , Html.pre [] + [ Html.code [] + [ Html.text + """viewItems = Array String -> String +viewItems items = + items + |> Array.sort + |> String.join ", " +""" + ] + ] + , Html.p [] + [ Html.text "In the " + , Html.a + [ Attribute.href "https://packages.gren-lang.org/package/gren-lang/browser/version/latest/overview" ] + [ Html.text "browser:" ] + ] + , Html.pre [] + [ Html.code [] + [ Html.text + """Html.p [] [ Html.text (viewItems model.items) ]""" + ] + ] + , Html.p [] + [ Html.text "In the " + , Html.a + [ Attribute.href "https://packages.gren-lang.org/package/gren-lang/node/version/latest/overview" ] + [ Html.text "terminal:" ] + ] + , Html.pre [] + [ Html.code [] + [ Html.text + """Stream.writeLineAsBytes (viewItems model.items) model.stdout""" + ] + ] + , Html.p [] + [ Html.text "On the " + , Html.a + [ Attribute.href "https://packages.gren-lang.org/package/gren-lang/node/version/latest/module/HttpServer" ] + [ Html.text "server:" ] + ] + , Html.pre [] + [ Html.code [] + [ Html.text + """response + |> Response.setHeader "Content-type" "text/csv" + |> Response.setBody (viewItems model.items) + |> Response.send +""" + ] + ] + ] ] } From 88cecb626d11bdbe2f5ad51b26b43345e7149d53 Mon Sep 17 00:00:00 2001 From: Justin Blake Date: Wed, 18 Dec 2024 05:49:28 -0500 Subject: [PATCH 2/5] Show people code as soon as possible on the page --- src/Page/Index.elm | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Page/Index.elm b/src/Page/Index.elm index 3494dcb..3023039 100644 --- a/src/Page/Index.elm +++ b/src/Page/Index.elm @@ -82,22 +82,6 @@ view _ _ _ = , Html.p [] [ Html.text "Programs written in Gren are simple, have few or no runtime exceptions and are fun to work with." ] ] - , Html.article - [] - [ Html.h3 [] - [ Html.text "Compiler as an assistant" ] - , Html.p [] - [ Html.text "Since side effects and error handling is represented in Gren's type system, the compiler can catch a lot of errors which are usually only discovered when the program is running in other languages." ] - , Html.p [] - [ Html.text "In Gren, a lot of time has been invested in how error messages are presented to you, so that the compiler feels more like a helpful assistant." ] - ] - , Html.article - [] - [ Html.h3 [] - [ Html.text "Efficiency" ] - , Html.p [] - [ Html.text "Gren produces small JavaScript files, and runs surprisingly fast. Applications written in Gren can be both smaller and faster than your average React-based application." ] - ] , Html.article [] [ Html.h3 [] @@ -154,5 +138,21 @@ viewItems items = ] ] ] + , Html.article + [] + [ Html.h3 [] + [ Html.text "Compiler as an assistant" ] + , Html.p [] + [ Html.text "Since side effects and error handling is represented in Gren's type system, the compiler can catch a lot of errors which are usually only discovered when the program is running in other languages." ] + , Html.p [] + [ Html.text "In Gren, a lot of time has been invested in how error messages are presented to you, so that the compiler feels more like a helpful assistant." ] + ] + , Html.article + [] + [ Html.h3 [] + [ Html.text "Efficiency" ] + , Html.p [] + [ Html.text "Gren produces small JavaScript files, and runs surprisingly fast. Applications written in Gren can be both smaller and faster than your average React-based application." ] + ] ] } From 9450b36da554e08b9c794588af1cb2861720da2d Mon Sep 17 00:00:00 2001 From: Justin Blake Date: Wed, 18 Dec 2024 06:21:36 -0500 Subject: [PATCH 3/5] Add error to compiler as assistant section --- src/Page/Index.elm | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Page/Index.elm b/src/Page/Index.elm index 3023039..785cec9 100644 --- a/src/Page/Index.elm +++ b/src/Page/Index.elm @@ -89,7 +89,7 @@ view _ _ _ = , Html.pre [] [ Html.code [] [ Html.text - """viewItems = Array String -> String + """viewItems : Array String -> String viewItems items = items |> Array.sort @@ -146,6 +146,32 @@ viewItems items = [ Html.text "Since side effects and error handling is represented in Gren's type system, the compiler can catch a lot of errors which are usually only discovered when the program is running in other languages." ] , Html.p [] [ Html.text "In Gren, a lot of time has been invested in how error messages are presented to you, so that the compiler feels more like a helpful assistant." ] + , Html.pre [] + [ Html.code [] + [ Html.span + [ Attribute.style "color" "rgb(36, 163, 175)" ] + [ Html.text "-- TYPE MISMATCH ------------------------------------------------- src/Main.gren\n\n" ] + , Html.text " The 1st argument to `viewItems` is not what I expect:\n\n14| Html.text (\"Item IDs: \" ++ (viewItems [1, 2, 3]))\n" + , Html.span + [ Attribute.style "color" "rgb(194, 54, 33)" ] + [ Html.text <| (String.repeat 45 " ") ++ "^^^^^^^^^\n" ] + , Html.text "This argument is an array of type:\n\n Array " + , Html.span + [ Attribute.style "color" "rgb(173, 173, 39)" ] + [ Html.text "number\n\n" ] + , Html.text "But `viewItems` needs the 1st argument to be:\n\n Array " + , Html.span + [ Attribute.style "color" "rgb(173, 173, 39)" ] + [ Html.text "String\n\n" ] + , Html.span + [ Attribute.style "text-decoration" "underline" ] + [ Html.text "Hint" ] + , Html.text ": Try using ", Html.span + [ Attribute.style "color" "rgb(40, 187, 28)" ] + [ Html.text "String.fromInt" ] + , Html.text " to convert it to a String?" + ] + ] ] , Html.article [] From 7a6e5a7d55ee6b23e5dbc7c9f78caa74b18cb9a8 Mon Sep 17 00:00:00 2001 From: Justin Blake Date: Wed, 18 Dec 2024 06:23:29 -0500 Subject: [PATCH 4/5] remove accidental extra space --- src/Page/Index.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Page/Index.elm b/src/Page/Index.elm index 785cec9..a688cd5 100644 --- a/src/Page/Index.elm +++ b/src/Page/Index.elm @@ -151,7 +151,7 @@ viewItems items = [ Html.span [ Attribute.style "color" "rgb(36, 163, 175)" ] [ Html.text "-- TYPE MISMATCH ------------------------------------------------- src/Main.gren\n\n" ] - , Html.text " The 1st argument to `viewItems` is not what I expect:\n\n14| Html.text (\"Item IDs: \" ++ (viewItems [1, 2, 3]))\n" + , Html.text "The 1st argument to `viewItems` is not what I expect:\n\n14| Html.text (\"Item IDs: \" ++ (viewItems [1, 2, 3]))\n" , Html.span [ Attribute.style "color" "rgb(194, 54, 33)" ] [ Html.text <| (String.repeat 45 " ") ++ "^^^^^^^^^\n" ] From 36c71e9dac74a8521d63bf71a38d7fab30a6f84e Mon Sep 17 00:00:00 2001 From: Justin Blake Date: Wed, 18 Dec 2024 06:27:02 -0500 Subject: [PATCH 5/5] Remove html functions from compiler error message Not required and reduced signal to noise on the example --- src/Page/Index.elm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Page/Index.elm b/src/Page/Index.elm index a688cd5..6a0a16d 100644 --- a/src/Page/Index.elm +++ b/src/Page/Index.elm @@ -151,10 +151,10 @@ viewItems items = [ Html.span [ Attribute.style "color" "rgb(36, 163, 175)" ] [ Html.text "-- TYPE MISMATCH ------------------------------------------------- src/Main.gren\n\n" ] - , Html.text "The 1st argument to `viewItems` is not what I expect:\n\n14| Html.text (\"Item IDs: \" ++ (viewItems [1, 2, 3]))\n" + , Html.text "The 1st argument to `viewItems` is not what I expect:\n\n14| \"Item IDs: \" ++ (viewItems [1, 2, 3])\n" , Html.span [ Attribute.style "color" "rgb(194, 54, 33)" ] - [ Html.text <| (String.repeat 45 " ") ++ "^^^^^^^^^\n" ] + [ Html.text <| (String.repeat 34 " ") ++ "^^^^^^^^^\n" ] , Html.text "This argument is an array of type:\n\n Array " , Html.span [ Attribute.style "color" "rgb(173, 173, 39)" ]