所以,我已经使用了几个Haskell XML库,包括hexpat和xml-enumerator.在阅读了真实世界Haskell(http://book.realworldhaskell.org/read/io.html)中的IO章节之后,我的印象是,如果我运行以下代码,那么在我浏览它时它将被垃圾收集.
但是,当我在一个大文件上运行时,内存使用量会随着运行而不断攀升.
runghc parse.hs bigfile.xml
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我的假设错了吗?地图/过滤器是否强制它评估所有内容?
import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.Lazy.UTF8 as U
import Prelude hiding (readFile)
import Text.XML.Expat.SAX
import System.Environment (getArgs)
main :: IO ()
main = do
args <- getArgs
contents <- BSL.readFile (head args)
-- putStrLn $ U.toString contents
let events = parse defaultParseOptions contents
mapM_ print $ map getTMSId $ filter isEvent events
isEvent :: SAXEvent String String -> Bool
isEvent (StartElement "event" as) = True
isEvent _ = False
getTMSId :: …Run Code Online (Sandbox Code Playgroud) 我们打算建立一个在线平台(API,服务器,数据,Wahoo!).对于上下文,假设我们需要构建类似于twitter的东西,但是在现场活动周围组织评论(推文).有关实况事件本身的信息必须尽可能快速且一致地提供给客户,而关于事件的评论可能需要等待一段时间才能交付.在现场活动结束后,我们会读得很重.
可伸缩性非常重要.我们想开始租用VPS切片,并从那里开始扩展.我是云的忠实粉丝,并希望尽可能长时间留在那里.我们可能会使用红宝石.
我确信我想尝试文档存储而不是RDBMS.我喜欢无模式存储的想法,以及通过关注键值来实现更容易扩展的承诺.
问题是我不知道哪种技术最适合我们的平台.我看过Couch,Mongo,Tokyo Cabinet,Cassandra和带有blobbed文档的RDBMS.有没有帮助为这个特定的工作选择合适的工具?
我正在制作游戏.游戏由无限平面组成.单位必须位于离散的方形上,因此它们可以简单地定位Location { x :: Int, y :: Int }
可能有很多种Unit.有些可能是生物,有些只是物体,比如一块石头或木头(想想那里的2d minecraft).许多人将是空的(只是草或其他).
你会如何在Haskell中建模?我考虑过做下面的事情,但是对象和生物呢?他们可能有不同的领域?在Unit上将它们全部归一化?
data Unit = Unit { x :: Int, y :: Int, type :: String, ... many shared properties... }
Run Code Online (Sandbox Code Playgroud)
我也考虑过拥有一个位置类型
data Location = Location { x :: Int, y :: Int, unit :: Unit }
-- or this
data Location = Location { x :: Int, y :: Int }
data Unit = Unit { unitFields... , location :: Location }
Run Code Online (Sandbox Code Playgroud)
你有什么想法?在OO语言中,我可能会拥有Location或Unit …
我正在尝试在osx上安装最新的happstack-server.他们只是添加了对libcryptopp的依赖,我无法让它工作.
~$ cabal install happstack-server
Resolving dependencies...
Configuring happstack-server-6.5.3...
cabal: Missing dependency on a foreign library:
* Missing C library: cryptopp
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
cabal: Error: some packages failed to install:
happstack-server-6.5.3 failed during the configure step. …Run Code Online (Sandbox Code Playgroud) 有没有办法在TypeScript中引用推断类型?
在下面的例子中,我们得到了很好的推断类型.
function Test() {
return {hello:"world"}
}
var test = Test()
test.hello // works
test.bob // 'bob' doesn't exist on inferred type
Run Code Online (Sandbox Code Playgroud)
但是,如果我想定义一个带有类型参数的函数:"Whatever Test返回",而不显式定义接口,该怎么办?
function Thing(test:???) {
test.hello // works
test.bob // I want this to fail
}
Run Code Online (Sandbox Code Playgroud)
这是一种解决方法,但如果Test具有自己的参数,它会变得毛茸茸.
function Thing(test = Test()) {} // thanks default parameter!
Run Code Online (Sandbox Code Playgroud)
有没有办法引用Test返回的推断类型?所以我可以输入"Whatever Test return",而无需创建界面?
我关心的原因是因为我通常使用闭包/模块模式而不是类.Typescript已经允许你输入一些类作为类,即使你可以创建一个描述该类的接口.我想输入一些函数返回而不是类.有关原因的更多信息,请参阅Typescript中的闭包(依赖注入).
解决这个问题的最佳方法是,TypeScript添加了定义模块的能力,这些模块将其依赖项作为参数,或者在闭包内定义模块.然后我可以使用spiffy export语法.有人知道这有什么计划吗?
javascript closures dependency-injection inferred-type typescript
我试图让RestKit和CoreData一起工作.我越来越近,但我收到以下错误:
CoreData: error: Failed to call designated initializer on NSManagedObject class 'Book'
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<Book 0x8454560> valueForUndefinedKey:]: the entity (null) is not key value coding-compliant for the key "title".'
Run Code Online (Sandbox Code Playgroud)
在我看来,它成功地找到了我的Book类,并且它有一个title属性.我究竟做错了什么?
Books.xcdatamodel
Book
title: String
Run Code Online (Sandbox Code Playgroud)
我有一个url at localhost:3000/books/initial返回以下(JSON)
[{title:"one"}, {title:"two"}]
Run Code Online (Sandbox Code Playgroud)
我正在使用mogenerator来创建我的课程.我没有添加任何内容Book,但_Book显然已定义title属性.
最后,这是我用来加载请求的代码.
RKObjectManager* objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://localhost:3000/"]];
RKManagedObjectStore* objectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:self.model];
objectManager.managedObjectStore = objectStore;
// Mappings
RKEntityMapping *bookMapping = [RKEntityMapping mappingForEntityForName:@"Book" inManagedObjectStore:objectStore];
[bookMapping addAttributeMappingsFromArray:@[@"title"]];
RKResponseDescriptor * …Run Code Online (Sandbox Code Playgroud) 我正在制作一个看起来很像http://pinterest.com的画廊的应用程序.在Pinterest中,当您单击某个图钉时,它会显示您正在查看的图库顶部的图钉页面.URL更改为pin url,并且不包含有关详细信息背后的库的任何信息.您可以单击"X"或在背景上返回您正在浏览的图库而无需重新加载.
如何使用UI-Router复制它?
需求:
谢谢!
你会使用if/else在Haskell中编写这个算法吗?没有它们有没有办法表达它?很难从具有意义的中间提取功能.这只是机器学习系统的输出.
我正在实现将html内容片段分类为此处描述的内容或Boilerplate的算法.这具有已经硬编码的权重.
curr_linkDensity <= 0.333333
| prev_linkDensity <= 0.555556
| | curr_numWords <= 16
| | | next_numWords <= 15
| | | | prev_numWords <= 4: BOILERPLATE
| | | | prev_numWords > 4: CONTENT
| | | next_numWords > 15: CONTENT
| | curr_numWords > 16: CONTENT
| prev_linkDensity > 0.555556
| | curr_numWords <= 40
| | | next_numWords <= 17: BOILERPLATE
| | | next_numWords > 17: CONTENT
| | curr_numWords > 40: CONTENT …Run Code Online (Sandbox Code Playgroud) Stack可以构建一个docker容器,使用该stack image container命令在服务器上运行您的应用程序(请参阅下面的参考资料).
如何连接到以这种方式创建的docker容器中的Web服务器?
我已经构建了一个简单的应用来证明这个问题.请在此处查看完整代码:https://github.com/seanhess/haskell-docker-example
这个应用程序是建立在stack new最小的变化.这是Main.hs.
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Network.Wai
import Network.HTTP.Types (status200)
import qualified Network.Wai.Handler.Warp as Warp
main :: IO ()
main = Warp.run 8010 app
app :: Application
app req respond = do
(putStrLn $ "Request: " ++ (show req))
(respond $ responseLBS status200 [] "Hello World")
Run Code Online (Sandbox Code Playgroud)
和stack.yaml
resolver: nightly-2016-06-12
image:
container:
name: haskell-docker-example
base: fpco/stack-run
Run Code Online (Sandbox Code Playgroud)
如果您在本地运行它,此应用程序将响应"Hello world".
stack build
stack exec haskell-docker-example
Run Code Online (Sandbox Code Playgroud)
但是如果你构建了docker镜像并启动它:
stack …Run Code Online (Sandbox Code Playgroud) 使用servant时,我想将所有错误作为JSON返回.目前,如果请求无法解析,我会看到这样的错误消息,以纯文本形式返回
Failed reading: not a valid json value
Run Code Online (Sandbox Code Playgroud)
相反,我想把它作为回报 application/json
{"error":"Failed reading: not a valid json value"}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?文档说ServantErr是默认的错误类型,我当然可以在处理程序中回应自定义错误,但如果解析失败,我看不出如何返回自定义错误.
haskell ×6
javascript ×2
algorithm ×1
angularjs ×1
cassandra ×1
closures ×1
core-data ×1
couchdb ×1
docker ×1
expat-parser ×1
if-statement ×1
ios ×1
json ×1
macos ×1
macports ×1
memory ×1
mogenerator ×1
mongodb ×1
objective-c ×1
rest ×1
restkit ×1
ruby ×1
servant ×1
stream ×1
typescript ×1
xml ×1