Live data from Hacker News

Haskell vs. Clojure (2014)

gist.github.com

51–55 of 55 posts

Re: Haskell vs. Clojure (2014)

#51
post #20

Earlier quoted context omitted.

Clojure has neither the cool constructs of CL (CLOS, conditions) nor the minimal design and fantastic set of control primitives of Scheme. In fact it has no significant advantage over Scheme aside from running on the JVM, and a few disadvantages (recur, why TF are lambda lists vectors?, etc.). It's different enough to be weird and annoying, but the differences aren't advantageous enough to make me want to switch: Sch…

recur I actually really like recur because it signifies intent. It tells the future-me that I intended for this function to be tail recursive (ie, it not being tail-recursive should be considered an error).

It does, but it's still too weak, e.g. it only works if the function is calling itself.

Re: Haskell vs. Clojure (2014)

#52
In F# you'd normally use a type provider for this kind of work, but for the sake of exercise:

    type Chapter = Map
    type Book    = Map
    type Bible   = Map
    
    let bookOrder = [|"Genesis"; "Exodus"; "Leviticus"; (* etc.. *) |]

    let sortChapter = Map.toSeq >> Seq.sortBy fst
                      >> Seq.toArray

    let sortBook = Map.map (fun _ -> sortChapter)
                   >> Map.toSeq >> Seq.sortBy fst
                   >> Seq.toArray

    let sortBible = Map.map (fun _ -> sortBook)
                    >> Map.toSeq >> Seq.sortBy (fun (bookname, _)-> Array.findIndex ((=) bookname) bookOrder)
                    >> Seq.toArray

    BIBLE_TEXT
    |> JsonConvert.DeserializeObject
    |> sortBible
    |> printfn "%A"
FP 101 suggests you could extract the Map.toSeq >> Seq.sortby x >> Seq.toArray function, but I don't think it gains any readability, and in any case it's just an artifact of the problem requiring an array output even though a Map would make more sense.

Re: Haskell vs. Clojure (2014)

#53

Obviously, Scala is better than either of those languages. #!/usr/bin/env amm import $ivy.`com.typesafe.play::play-json:2.5.8` import java.nio.file._, play.api.libs.json._ val bookOrder = Seq( "Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy", "Joshua", "Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings", "1 Chronicles", "2 Chronicles", "Ezra", "Nehemiah", "Esther", "Job", "Psalms", "Proverbs", "E…

Code golf? Code golf!

    let o = [|"Genesis"; "Exodus"; "Leviticus"; "Numbers"; "Deuteronomy";
              "Joshua"; "Judges"; "Ruth"; "1 Samuel"; "2 Samuel"; "1 Kings"; "2 Kings";
              "1 Chronicles"; "2 Chronicles"; "Ezra"; "Nehemiah"; "Esther"; "Job";
              "Psalms"; "Proverbs"; "Ecclesiastes"; "Song of Solomon"; "Isaiah";
              "Jeremiah"; "Lamentations"; "Ezekiel"; "Daniel"; "Hosea"; "Joel"; "Amos";
              "Obadiah"; "Jonah"; "Micah"; "Nahum"; "Habakkuk"; "Zephaniah"; "Haggai";
              "Zechariah"; "Malachi"; "Matthew"; "Mark"; "Luke"; "John"; "Acts";
              "Romans"; "1 Corinthians"; "2 Corinthians"; "Galatians"; "Ephesians";
              "Philippians"; "Colossians"; "1 Thessalonians"; "2 Thessalonians";
              "1 Timothy"; "2 Timothy"; "Titus"; "Philemon"; "Hebrews"; "James";
              "1 Peter"; "2 Peter"; "1 John"; "2 John"; "3 John"; "Jude"; "Revelation"|]

    let a s = Map.toSeq >> Seq.sortBy s >> Seq.toArray

    JsonConvert.DeserializeObject BIBLE_TEXT    
    |> Map.map (fun _ -> Map.map (fun _ -> a fst) >> a fst)
    |> a (fun (n, _) -> Array.findIndex ((=) n) o)
    |> printfn "%A"

Re: Haskell vs. Clojure (2014)

#54
post #53

Obviously, Scala is better than either of those languages. #!/usr/bin/env amm import $ivy.`com.typesafe.play::play-json:2.5.8` import java.nio.file._, play.api.libs.json._ val bookOrder = Seq( "Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy", "Joshua", "Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings", "1 Chronicles", "2 Chronicles", "Ezra", "Nehemiah", "Esther", "Job", "Psalms", "Proverbs", "E…

Code golf? Code golf! let o = [|"Genesis"; "Exodus"; "Leviticus"; "Numbers"; "Deuteronomy"; "Joshua"; "Judges"; "Ruth"; "1 Samuel"; "2 Samuel"; "1 Kings"; "2 Kings"; "1 Chronicles"; "2 Chronicles"; "Ezra"; "Nehemiah"; "Esther"; "Job"; "Psalms"; "Proverbs"; "Ecclesiastes"; "Song of Solomon"; "Isaiah"; "Jeremiah"; "Lamentations"; "Ezekiel"; "Daniel"; "Hosea"; "Joel"; "Amos"; "Obadiah"; "Jonah"; "Micah"; "Nahum"; "Habak…

F#, right?

Re: Haskell vs. Clojure (2014)

#55
post #53

Earlier quoted context omitted.

Code golf? Code golf! let o = [|"Genesis"; "Exodus"; "Leviticus"; "Numbers"; "Deuteronomy"; "Joshua"; "Judges"; "Ruth"; "1 Samuel"; "2 Samuel"; "1 Kings"; "2 Kings"; "1 Chronicles"; "2 Chronicles"; "Ezra"; "Nehemiah"; "Esther"; "Job"; "Psalms"; "Proverbs"; "Ecclesiastes"; "Song of Solomon"; "Isaiah"; "Jeremiah"; "Lamentations"; "Ezekiel"; "Daniel"; "Hosea"; "Joel"; "Amos"; "Obadiah"; "Jonah"; "Micah"; "Nahum"; "Habak…

F#, right?

Yup.

'Minified', for fun:

    let a s=Map.toSeq>>Seq.sortBy s>>Seq.toArray
    let m f=Map.map(fun _->f)  
    printfn"%A"(a(fun(n, _)->Array.findIndex((=)n)o)(m(m(a fst)>>a fst)(JsonConvert.DeserializeObjectBIBLE_TEXT)))
Post reply on HN