Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (0)

Powered by Vanilla. Made with Bootstrap.
[Haskell] mirrorrank
  • Deque
    Posts: 78
    I made a little script that takes a newly updated mirrorlist, removes all comments from the german servers and calls rankmirrors with this new list afterwards to sort the mirrors by speed. It just automates the process of doing this (under "Sorting mirrors").

    I know that this is not much, I just thought it might be interesting.

    import Data.List
    import System.Cmd

    main = do
    x <- readFile \"/etc/pacman.d/mirrorlist.pacnew\"
    writeFile \"/etc/pacman.d/mirrorlist.backup\" $ unlines (prepareList (lines x))
    system \"rankmirrors -n 6 /etc/pacman.d/mirrorlist.backup > /etc/pacman.d/mirrorlist\"

    prepareList :: [String] -> [String]
    prepareList xss = _prepareList xss \"German\" \"#\" \"Server\"

    _prepareList :: Eq a => [[a]] -> [a] -> [a] -> [a] -> [[a]]
    _prepareList xss start comment server = case xss of
    [] -> []
    xs : xss' -> if contains xs start
    then [xs] ++ (removeComments xss' comment server)
    else [xs] ++ (_prepareList xss' start comment server)

    removeComments :: Eq a => [[a]] -> [a] -> [a] -> [[a]]
    removeComments xss comment server = case xss of
    [] -> []
    xs : xss' -> if contains xs server
    then [drop 1 xs] ++ (removeComments xss' comment server)
    else xs : xss'

    contains :: Eq a => [a] -> [a] -> Bool
    contains xs [] = True
    contains xs (y : ys') = case xs of
    [] -> False
    x : xs' -> if x == y
    then contains xs' ys'
    else contains xs' (y : ys')
  • D0WNGRADE
    Posts: 220
    Looks nice, I've never seen Haskell in action. :P
  • Mr. P-teoMr. P-teo
    Posts: 269
    Looks reli nice, am i able to add this to my site - http://www.sourcex.info, you will be put down as creator of it.
    Skype: mrpt3o
    Twitter: MrPteo


    image
  • Deque
    Posts: 78
    Thx, DOWNGRADE. I don't want to get rusty in Haskell. I don't use it much except for configuring xmonad.

    said:


    Looks reli nice, am i able to add this to my site - http://www.sourcex.info, you will be put down as creator of it.


    Yes, you can.
  • Sh3llc0d3
    Posts: 1,910
    First time I've seen Haskell implemented too. What would you say the major implementations of Haskell are? Anything in particular it's used for?
  • Deque
    Posts: 78
    Haskell was created by mathematicians and because of that is used a lot by mathematicians (i.e. the programs can be very easily mathematically proved to be correct which is what mathematicians need). So I guess a lot implementations are math related. It is also very good for parallel tasks, because the functions usually have no side effects (and if so, they are marked by their type). But you can do anything with it. xmonad, the window manager I use, is written in Haskell.
  • Sh3llc0d3
    Posts: 1,910
    said:


    Haskell was created by mathematicians and because of that is used a lot by mathematicians (i.e. the programs can be very easily mathematically proved to be correct which is what mathematicians need). So I guess a lot implementations are math related. It is also very good for parallel tasks, because the functions usually have no side effects (and if so, they are marked by their type). But you can do anything with it. xmonad, the window manager I use, is written in Haskell.



    Sounds like quite a useful language for math-based encryption/decryption. Thanks for the info :)