Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import qualified Data.List as L
  2. import System.Environment
  3. import Data.Array.IArray
  4. import Data.Function
  5.  
  6. main = do
  7.     (sourcefile:_) <- getArgs
  8.     sourcedata <- readFile sourcefile
  9.     let tships = lines sourcedata
  10.         header = take 3 tships
  11.         rest = drop 3 $ tships
  12.         parsedlist = map split rest
  13.         arrayedlist = map mkarray parsedlist
  14.         processedlist = map preprocess arrayedlist
  15.         finallist = map process processedlist
  16.         listedfinal = map mklist finallist
  17.         stuff = unlines $ header ++ map unsplit listedfinal
  18.     writeFile "done.txt" stuff
  19.  
  20. mkarray list = listArray (0, (length list - 1)) list
  21. mklist :: Array Int String-> [String]
  22. mklist myarray = elems myarray
  23.  
  24. split :: String -> [String]
  25. split = filter (not . L.any (== ';')) . L.groupBy (on (==) (== ';')) -- like words, but for ;. Also like Data.ByteString split, but partially applied with ';'
  26.  
  27.  
  28. unsplit :: [String] -> String
  29. unsplit = L.intercalate ";"
  30.  
  31. process myarray = myarray // [(2,show fixp),(3,show fixy),(4,show fixroll),(7,show fixspeed),(8,show fixaccel)]
  32.     where   pitch = read $ myarray ! 2
  33.         yaw = read $ myarray ! 3
  34.         roll = read $ myarray ! 4
  35.         speed = read $ myarray ! 7
  36.         accel = read $ myarray ! 8
  37.         normalize num mid factor = num + (mid - num) / factor
  38.         fixp = normalize pitch 1 5
  39.         fixy = normalize yaw 1 5
  40.         fixroll = normalize roll 1 5
  41.         fixspeed = floor $ normalize speed 500000 15
  42.         fixaccel = floor $ normalize (2 * accel) 200000 15
  43.        
  44. preprocess myarray
  45.     | tunings > 15 = fixarray myarray
  46.     | otherwise = myarray
  47.     where   tunings = read $ myarray ! 26
  48.         fixarray passedarray = passedarray // [(7, show fixedspeed),(8, show fixedaccel),(26, "15")]
  49.         fixedspeed = floor $ originalspeed * ( 1 + (tunings - 15) * 0.1)
  50.         fixedaccel =  floor $ originalaccel * ( 1 + originalspeed / (fixedspeed - originalspeed))
  51.         originalspeed = read $ myarray ! 7
  52.         originalaccel = read $ myarray ! 8
  53.  
  54. [1 of 1] Compiling Main             ( new  2.hs, new  2.o )
  55.  
  56. new  2.hs:49:15:
  57.     Ambiguous type variable `a' in the constraints:
  58.      `Integral a' arising from a use of `floor' at new  2.hs:49:15-19
  59.      `RealFrac a' arising from a use of `floor' at new  2.hs:50:16-20
  60.      `Read a' arising from a use of `read' at new  2.hs:47:17-20
  61.    Probable fix: add a type signature that fixes these type variable(s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement