- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个问题可能是也可能不是真正的 Haskell 特定问题,但它涉及到我在执行某个编程任务时遇到的一点烦恼。
我用 Haskell 编写了一个程序,该程序对于我要解决的问题类型来说基本上是通用的,但包含两个依赖组件:脚本的运行时估计函数,根据某个基准的试运行进行计算,以及一个文件名转换函数,该函数是根据我正在使用的文件的命名方案定制的。当然,如果我想使用具有基准测试之外的性能的脚本,或者我发现估计过于保守,我想更改用于估计运行时间的函数,同样我希望能够如果我需要使用不同命名方案的不同文件,请修改文件名转换函数。
但是,我运行脚本的(远程)计算机没有安装 GHC 或 runhaskell,因此我必须从本地计算机修改、编译和重新上传代码,这有点麻烦一个麻烦。我的问题是,是否有一种简单的方法可以在代码的某些组件中实现更改,而无需重新编译以便在调用时反射(reflect)更改?
如果我的描述含糊不清,我深表歉意,并且在下面包含了血淋淋的细节,因为如果事实证明这些细节是不必要的,我不想从一开始就用不必要的细节来混淆我的问题。
我用 Haskell 编写这段代码主要是因为这是我最了解如何实现方法的语言;虽然我知道其他语言可能更可移植,但我对其他语言还不够熟悉,因此我无法在无需阅读大量文档并经过多次修订才能实现这一点的情况下实现这一点。如果用 Haskell 实现我想要的灵 active 是不切实际的,我可以理解这一点,但我宁愿知道 Haskell 无法做到这一点,也不愿收到其他可以做到这一点的语言的建议。
我正在编写代码以在负载共享集群上运行独立作业,因此我希望最准确地估计特定作业所需的时间,而不会低于预期并导致作业终止,也不会过度估计拍摄,从而降低作业的优先级。我的时间估计基于作业程序输入的大小,并且我已经收集了足够的实际数据来推导出大小和时间之间的近似二次关系。
我目前为输入分配时间估计并由此建立作业订单的方式是使用 Haskell 脚本解析 du 的输出,执行计算并写入时间结果保存到一个新文件中,然后由作业分配脚本循环读取该文件。
该作业正在针对配对文件运行,这些文件在某种程度上共享一个通用名称,其中我希望保留的最后一个通用元素是“s”,从那时起,两个名称中都不再有“s”字符在。因此,我向后遍历名称并下降,直到到达“s”。我的代码包含在下面。它的评论很自由,这可能会有所帮助,也可能会造成困惑。其中一些对于我正在处理的任务非常具体。
-- size2time.hs
-- A Haskell script to convert file sizes into job-times, based on observed job-times for
-- various file sizes
--
--
-- This file may be compiled via the following command:
-- > ghc size2time.hs
--
-- Should any edits be made, ensure that the compiled executable is updated accordingly
--
-- The executable is to be run with the following usage
--
-- > ./size2time inputfile outputfile
--
-- where inputfile is the name of a file whose first column contains the sizes, in MB, of each fq.gz
-- (including both paired-end reads), and whose second column contains the corresponding file names, as
-- generated by
--
-- > du -m $( ls DIR/*.fq.gz ) >inputfile
--
-- where DIR is the directory containing the fq.gz files
--
-- output is the name of a file that will be created by the execution of this script, whose first
-- column will contain the run-time, in minutes, of the corresponding job (the times are based on
-- jobs run on Intel CPUs with 12 cores and 2GB of RAM, and therefore will potentially be
-- inapplicable to jobs run on CPUs of different manufacturers, with different numbers of cores,
-- and/or with different allocated RAM), and whose second column contains the scrubbed names of
-- the jobs to be run. The greater time-value for any given pair is used, with only one member of
-- each pair retained, as the file-names of each member of a pair are identical after scrubbing
--
-- import modules for command line arguments, list operations, map operations
import System.Environment
import Data.List
import qualified Data.Map as Map
main = do
args <- getArgs -- parse command line arguments: inputfile, outputfile, <ignored>
let infile = head args
outfile = head . tail $ args
contents <- readFile infile -- read the inputfile
let sf = lines contents -- split into lines
tf = map size2time sf -- peform size2time mapping
st = map sample tf -- scrub filename
stu = Map.toList . Map.fromListWith (max) $ st -- take only the longer of the two times of the paired reads
tsu = map flip2 stu -- put time first
stsu = sort tsu -- sort by time, ascending
tsustr = map unwords . map (\(x,y) -> [show x, y]) $ stsu -- convert back to string
tsulns = unlines tsustr -- join individual lines
writeFile outfile tsulns -- write to the outputfile
{- given a string, with the size of a file and the name of the file,
- returns a tuple with the estimated job-time and the unmodified name
- of the file.
-
- The size-time conversion is extrapolated from experimental data,
- with only the upper extremes considered in order to prevent timeout,
- rounding in the quadratic term, and a linear-degree time padding added
- to allow for upper extremes. If modifications are to be made to any
- coefficients, it is recommended that only linear and constant terms be increased,
- and decreases should only be made after performing sufficient alignments to collect
- enough (file size)--(actual computation time) pairs to verify that the padding is excessive,
- and to determine coefficients that more closely follow the trend of the actual data, with
- the conditions that no data point must exceed the approximation curve, and that sufficient padding
- must be provided to allow for potential inconsistency in the time required for any given size of alignment.
-}
size2time :: String -> (Int,String)
size2time sfstring = let (size:file:[]) = words sfstring -- parses out size and filename
x = fromIntegral (read size :: Int) -- floating point from numeric string
time = floor $ 0.000025 * x ^ 2 + 0.03 * x + 10 -- apply floored conversion
tfstring = (time,file)
in tfstring
{-
- removes all characters in the file-name after 's', which properly scrubs files of the format
- *--Hs--R?.fq.gz, where the ? is either 1 or 2. For filenames formatted in different ways,
- or for alternative naming of the BAM file to be generated, this function must be modified
- to suit the scenario.
-}
sample :: (a,String) -> (String,a)
sample (x,f) = let s = reverse . dropWhile (/= 's') . reverse $ f
in (s,x)
{-
- Reverses the order of a tuple, e.g. so that a Map may be made with a key to be found in the
- current second position of the tuple.
-}
flip2 :: (a,b) -> (b,a)
flip2 (x,y) = (y,x)
最佳答案
我认为您的问题没有明确的解决方案。
如果远程计算机上没有解释器或编译器,则无法修改该计算机上的 Haskell 源代码,然后将其转换为机器可读的形式。
正如其他人所说,也许您可以实现配置文件或命令行选项,以允许在运行时指定可能被修改的数据。
或者,假设您的远程计算机安装了 gcc
,您可以让 GHC 在本地计算机上将 Haskell 代码编译为 C,然后将其传输到远程计算机,尽力了解如何实现它翻译您的代码,并对 C 代码进行更改并在远程计算机上重新编译。
关于haskell - 在没有 GHC 的机器上运行 Haskell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26062350/
在 Haskell 中,类型声明使用双冒号,即 (::),如 not::Bool -> Bool。 但是在许多语法与 Haskell 类似的语言中,例如榆树、 Agda 、他们使用单个冒号(:)来声明
insertST :: StateDecoder -> SomeState -> Update SomeState SomeThing insertST stDecoder st = ... Stat
如果这个问题有点含糊,请提前道歉。这是一些周末白日梦的结果。 借助 Haskell 出色的类型系统,将数学(尤其是代数)结构表达为类型类是非常令人愉快的。我的意思是,看看 numeric-prelud
我有需要每 5 分钟执行一次的小程序。 目前,我有执行该任务的 shell 脚本,但我想通过 CLI 中的键为用户提供无需其他脚本即可运行它的能力。 实现这一目标的最佳方法是什么? 最佳答案 我想你会
RWH 面世已经有一段时间了(将近 3 年)。在在线跟踪这本书的渐进式写作之后,我渴望获得我的副本(我认为这是写书的最佳方式之一。)在所有相当学术性的论文中,作为一个 haskell 学生,读起来多么
一个经典的编程练习是用 Lisp/Scheme 编写一个 Lisp/Scheme 解释器。可以利用完整语言的力量来为该语言的子集生成解释器。 Haskell 有类似的练习吗?我想使用 Haskell
以下摘自' Learn You a Haskell ' 表示 f 在函数中用作“值的类型”。 这是什么意思?即“值的类型”是什么意思? Int 是“值的类型”,对吗?但是 Maybe 不是“值的类型”
现在我正在尝试创建一个基本函数,用于删除句子中的所有空格或逗号。 stringToIntList :: [Char] -> [Char] stringToIntList inpt = [ a | a
我是 Haskell 的新手,对模式匹配有疑问。这是代码的高度简化版本: data Value = MyBool Bool | MyInt Integer codeDuplicate1 :: Valu
如何解释这个表达式? :t (+) (+3) (*100) 自 和 具有相同的优先级并且是左结合的。我认为这与 ((+) (+3)) (*100) 相同.但是,我不知道它的作用。在 Learn
这怎么行 > (* 30) 4 120 但这不是 > * 30 40 error: parse error on input ‘*’ 最佳答案 (* 30) 是一个 section,它仍然将 * 视为
我想创建一个函数,删除满足第二个参数中给定谓词的第一个元素。像这样: removeFirst "abab" ( 'b') = "abab" removeFirst [1,2,3,4] even =
Context : def fib(n): if n aand returns a memoized version of the same function. The trick is t
我明白惰性求值是什么,它是如何工作的以及它有什么优势,但是你能解释一下 Haskell 中什么是严格求值吗?我似乎找不到太多关于它的信息,因为惰性评估是最著名的。 他们各自的优势是什么。什么时候真正使
digits :: Int -> [Int] digits n = reverse (x) where x | n digits 1234 = [3,1,2,4]
我在 F# 中有以下代码(来自一本书) open System.Collections.Generic type Table = abstract Item : 'T -> 'U with ge
我对 Haskell 比较陌生,过去几周一直在尝试学习它,但一直停留在过滤器和谓词上,我希望能得到帮助以帮助理解。 我遇到了一个问题,我有一个元组列表。每个元组包含一个 (songName, song
我是 haskell 的初学者,我试图为埃拉托色尼筛法定义一个简单的函数,但它说错误: • Couldn't match expected type ‘Bool -> Bool’
我是 Haskell 语言的新手,我在使用 read 函数时遇到了一些问题。准确地说,我的理解是: read "8.2" + 3.8 应该返回 12.0,因为我们希望返回与第二个成员相同的类型。我真正
当我尝试使用真实项目来驱动它来学习 Haskell 时,我遇到了以下定义。我不明白每个参数前面的感叹号是什么意思,我的书上好像也没有提到。 data MidiMessage = MidiMessage
我是一名优秀的程序员,十分优秀!