Merge pull request #172 from seanyu4296/add-purescript-solution-for-chapter-1-chapter-2
Add purescript solution for chapter 1 chapter 2
This commit is contained in:
6
02_selection_sort/Purescript/README.md
Normal file
6
02_selection_sort/Purescript/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# Getting Started
|
||||
1. Install `spago` and `purescript` through `yarn` or `npm` (e.g. `yarn global add spago` and `yarn global add purescript`)
|
||||
2. Run file through `spago run --watch --main <module-name>` (e.g. `spago run --watch --main GrokkingAlgos.SelectionSort`)
|
||||
|
||||
# Main Repo
|
||||
- https://github.com/seanyu4296/grokking-algo-in-purs
|
||||
17
02_selection_sort/Purescript/SelectionSort.purs
Normal file
17
02_selection_sort/Purescript/SelectionSort.purs
Normal file
@@ -0,0 +1,17 @@
|
||||
module GrokkingAlgos.SelectionSort where
|
||||
|
||||
import Prelude
|
||||
import Data.Foldable (minimum)
|
||||
import Data.List (List(..), delete, (:))
|
||||
import Data.Maybe (Maybe(..))
|
||||
import Effect (Effect)
|
||||
import Effect.Class.Console (logShow)
|
||||
|
||||
selectionsort :: List Int -> List Int
|
||||
selectionsort l = case minimum l of
|
||||
Nothing -> Nil
|
||||
Just min -> min : selectionsort (delete min l)
|
||||
|
||||
main :: Effect Unit
|
||||
main = do
|
||||
logShow $ selectionsort $ 1 : 2 : 3 : 5 : 4 : Nil
|
||||
8
02_selection_sort/Purescript/packages.dhall
Normal file
8
02_selection_sort/Purescript/packages.dhall
Normal file
@@ -0,0 +1,8 @@
|
||||
let upstream =
|
||||
https://github.com/purescript/package-sets/releases/download/psc-0.13.8-20200724/packages.dhall sha256:bb941d30820a49345a0e88937094d2b9983d939c9fd3a46969b85ce44953d7d9
|
||||
|
||||
let overrides = {=}
|
||||
|
||||
let additions = {=}
|
||||
|
||||
in upstream // overrides // additions
|
||||
9
02_selection_sort/Purescript/spago.dhall
Normal file
9
02_selection_sort/Purescript/spago.dhall
Normal file
@@ -0,0 +1,9 @@
|
||||
{-
|
||||
Welcome to a Spago project!
|
||||
You can edit this file as you like.
|
||||
-}
|
||||
{ name = "my-project"
|
||||
, dependencies = [ "console", "effect", "psci-support", "arrays", "debug", "lists", "ordered-collections", "strings"]
|
||||
, packages = ./packages.dhall
|
||||
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
|
||||
}
|
||||
Reference in New Issue
Block a user