我是哈斯凯尔的新手.
如果我输入GHCi(7.10.3):
:info (:)
Run Code Online (Sandbox Code Playgroud)
我得到结果:
*** Parser:
data [] a = ... | a : [a] -- Defined in ‘GHC.Types’
infixr 5 :
data [] a = ... | a : [a] -- Defined in ‘GHC.Types’
infixr 5 :
Run Code Online (Sandbox Code Playgroud)
这是否意味着运算符被定义了两次?我在源中找不到任何可疑的东西= /
目前我正在编写一个Sinatra应用程序,它从用户那里获取一些图片并返回一张新图片.
有一部分haml形式:
%input{type:'file', name:'user_image'}
Run Code Online (Sandbox Code Playgroud)
还有来自处理程序的代码:(蒙太奇是另一张图片)
source_userpic = params[:user_image][:tempfile]
blob = File.open(source_userpic).read
userpic = ImageList.new
userpic.from_blob(blob)
resized_img = userpic.scale(montage.columns,
montage.rows)
resized_img.opacity = MaxRGB/3
Run Code Online (Sandbox Code Playgroud)
然后两个图像"复合"并存储(不需要)
final_picture = ImageList.new
final_picture << montage.composite(resized_img, 0, 0, OverCompositeOp)
final_picture.write("./public/uploads/#{DateTime.now}.jpg" # dirty (for example)
Run Code Online (Sandbox Code Playgroud)
接下来,我需要使用ajax显示final_picture.有两个明显的问题:第一,我不需要保存final_picture - 它只是预览,第二,我必须编写代码以避免文件名冲突...
如何发送final_picture来查看?to_blob方法?但下一步是什么?
我有一个对结构列表[("oct",1),("nov",1),("dec",1)]
我想计算对内的总和:[("oct",1),("nov",2),("dec",3)]。我认为这是单子实现的一个很好的例子,但无法弄清楚如何保存容器。
我尝试在列表上创建函数(我已经知道了scanl1,只是在这里展示努力:)
csm (x:[]) = [x]
csm (x:y:xs) = x : csm ((x + y) : xs)
Run Code Online (Sandbox Code Playgroud)
然后尝试类似的事情:
sumOnPairs l = do
pair <- l
return (csm (snd pair))
Run Code Online (Sandbox Code Playgroud)
我的解决方案不起作用,请为我指出正确的方向