Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

HASKELL LIST HELP

Name: Anonymous 2011-01-12 11:54

HELLO

I HAVE A LIST sortList OF INTEGERS 1..n AND A LIST elemList OF n ELEMENTS. HERE'S WHAT I WANT TO DO:

sortList: [3,2,4,1]
elemList: ["HAX", "MY", "ANUS", "ONIICHAN"]

proggleSort sortList elemList
=>
["ANUS", "MY", "ONIICHAN" "HAX"]

HOW WOULD I IMPLEMENT THE proggleSort?

Name: Anonymous 2011-01-12 12:00


proggleSort (x:xs) elem = (elem !! (x-1)):proggleSort xs elem
proggleSort _ _         = []

5 seconds, did I do it right?

Name: Anonymous 2011-01-12 12:00

I'll assume you know how to progressively get each list element in order from first to last, how to append a new element to the end of a list, and basic file IO and string operations.

Take elemList and write each element to a text file, named 1.txt, 2.txt, and so on.

Then take sortList, convert each element to a string, append ".txt", open the corresponding file, and insert its contents onto the result list.

There are more elegant solutions to this problem, but this one will leave your teacher with little doubt it's your own work.

Name: Anonymous 2011-01-12 12:05

>>1
Use a {i real} programming language:
> (sort '("/b/" "to" "Back") (λ (x y) (char-ci>? (string-ref x 0) (string-ref x 1))))
'("Back" "to" "/b/")

Name: Anonymous 2011-01-12 12:11

>>3
Take elemList and write each element to a text file,
This is how I wanted to emulate state when I was learning Haskell.

Name: Fuck off, !Ep8pui8Vw2 2011-01-12 12:39

>>4
Fuck off, ``lispfag''.

Name: Anonymous 2011-01-12 12:48

asked 53 mins ago

+--+
xarnfan29
|XF| 12 ●1
+--+ 50% accept rate

Name: Anonymous 2011-01-12 13:03

>>1
proggleSort = map snd . sort . zip

Name: Anonymous 2011-01-12 13:25

>>8
YES THANK YOU FOR HASKELL "LOOK AND FEEL"
>>2 YOUR A FAGGOT

Name: Anonymous 2011-01-12 13:43

>>9
It's called point-less programming.

Name: Anonymous 2011-01-12 13:46

use lisp

Name: Anonymous 2011-01-12 13:53

Name: Anonymous 2011-01-12 16:02

>>8 doesn't work

proggleSort = (map snd . sort) `dot` zip
    where dot = (.).(.)

Name: Anonymous 2011-02-03 4:30

Don't change these.
Name: Email:
Entire Thread Thread List