haskell加载模块列表中

haskell加载模块列表中

本文介绍了haskell加载模块列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿haskellers和haskellettes,
有可能在列表中加载模块函数。
在我的具体情况中,我有一个函数列表,所有检查或

  checkRules :: [Nucleotide]  - > ; Bool 
checkRules nucs =或$ map($ nucs)[checkRule1,checkRule2]

i从单独的模块中导入checkRule1和checkRule2 - 我不知道以后我是否还需要更多它们。



我想要具有相同的功能看起来像

   - 从规则中导入所有函数作为规则,其中
- :t rules ~~> [([Nucleotide] - > Bool)]

checkRules :: [Nucleotide] - > Bool
checkRules nucs =或$ map($ nucs)规则

程序排序伪核苷酸根据给定的规则对可行和不可行序列进行序列分析。
预先感谢ε/ 2






附录:
所以我认为是对的 - 我需要:


  genList :: File  - > TypeSignature  - > [TypeSignature] 
chckfun ::(a-> b) - > TypeSignature - > Bool

在编译时。
但我无法生成模块中所有函数的列表 - 因为它们很可能没有相同的类型签名,因此并不是所有函数都适合在一个列表中。所以我不能用chckfun过滤给定的列表。




  • 为了做到这一点,我要么检查源文件中的写入类型签名?)或编译器给出的推理类型(?)。
  • 我想到的另一个问题是:并非写入源文件的每个函数都可能导出? / p>


  • 这是一个haskell初学者在学习5个月后应该尝试解决的问题 - 毕竟这个编译时间思考之后,我的大脑被塑造成一个克莱恩的瓶子,

  • a href =http://hackage.haskell.org/packages/archive/language-haskell-extract/0.2.0/doc/html/Language-Haskell-Extract.html> language-haskell-extract 。特别是,模板Haskell函数 functionExtractor 接受一个正则表达式,并返回匹配的顶级绑定列表,如(name,value)对。

      { - #LANGUAGE TemplateHaskell# - } $ b只要它们都具有匹配的类型, $ b import Language.Haskell.Extract 

    myFoo =Hello
    myBar =World

    allMyStuff = $(functionExtractor^ my)

    main = print allMyStuff

    输出:

      [(myFoo,Hello),(myBar,World)] 


    Hey haskellers and haskellettes,is it possible to load a module functions in a list.in my concrete case i have a list of functions all checked with or

    checkRules :: [Nucleotide] -> Bool
    checkRules nucs = or $ map ($ nucs) [checkRule1, checkRule2]
    

    i do import checkRule1 and checkRule2 from a seperate module - i don't know if i will need more of them in the future.

    i'd like to have the same functionality look something like

    -- import all functions from Rules as rules where
    -- :t rules ~~> [([Nucleotide] -> Bool)]
    
    checkRules :: [Nucleotide] -> Bool
    checkRules nucs = or $ map ($ nucs) rules
    

    the program sorts Pseudo Nucleotide Sequences in viable and nonviable squences according to given rules.thanks in advance ε/2


    Addendum:So do i think right - i need:

    genList :: File -> TypeSignature -> [TypeSignature]
    chckfun :: (a->b) -> TypeSignature -> Bool
    

    at compile time.but i can't generate a list of all functions in the module - as they most probably will have not the same type signature and hence not all fit in one list. so i cannot filter given list with chckfun.

    • In order to do this i either want to check the written type signatures in the source file (?) or the inferenced types given by the compiler(?).
    • another problem that comes to my mind is: not every function written in the source file might get exported ?

    • Is this a problem a haskell beginner should try to solve after 5 months of learning - my brain is shaped like a klein's bottle after all this "compile time thinking".

    解决方案

    There is a nice package on Hackage just for this: language-haskell-extract. In particular, the Template Haskell function functionExtractor takes a regular expression and returns a list of the matching top level bindings as (name, value) pairs. As long as they all have matching types, you're good to go.

    {-# LANGUAGE TemplateHaskell #-}
    import Language.Haskell.Extract
    
    myFoo = "Hello"
    myBar = "World"
    
    allMyStuff = $(functionExtractor "^my")
    
    main = print allMyStuff
    

    Output:

    [("myFoo", "Hello"), ("myBar", "World")]
    

    这篇关于haskell加载模块列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 11:40