小编Ner*_*Guy的帖子

我如何putStrLn Data.ByteString.Internal.ByteString?

我正在学习haskell,并决定尝试编写一些小的测试程序来使用Haskell代码和使用模块.目前我正在尝试使用第一个参数使用Cypto.PasswordStore创建密码哈希.为了测试我的程序,我试图从第一个参数创建一个哈希,然后将哈希打印到屏幕.

import Crypto.PasswordStore
import System.Environment

main = do
    args <- getArgs
    putStrLn (makePassword (head args) 12)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

testmakePassword.hs:8:19:
    Couldn't match expected type `String'
            with actual type `IO Data.ByteString.Internal.ByteString'
    In the return type of a call of `makePassword'
    In the first argument of `putStrLn', namely
      `(makePassword (head args) 12)'
    In a stmt of a 'do' block: putStrLn (makePassword (head args) 12)
Run Code Online (Sandbox Code Playgroud)

我一直在使用以下链接作为参考,但我现在只是试错了无济于事. http://hackage.haskell.org/packages/archive/bytestring/0.9.0.4/doc/html/Data-ByteString-Internal.html http://hackage.haskell.org/packages/archive/pwstore-purehaskell/2.1 /doc/html/Crypto-PasswordStore.html

string io haskell output

7
推荐指数
2
解决办法
2065
查看次数

GHC - 没有(Monad Ptr)的实例

我是haskell的新手,我正在尝试编写我的第一个haskell C库.这是我第一次使用Foreign.C模块.我在示例中迷失了,并且陷入困境.这是我到目前为止所提出的:

{-# LANGUAGE ForeignFunctionInterface #-}

module Grep where

import GHC.Ptr
import Foreign.C.String
import Data.List (isInfixOf)

grep :: CString -> CString -> CString
grep i s = do
    ii <- peekCString i
    ss <- peekCString s
    g <- newCString (isInfixOf ii ss)
    g 

foreign export ccall grep :: CString -> CString -> CString
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

PS C:\Users\GGuy\Source\haskell> ghc -c -O grep.hs

grep.hs:11:9:
  No instance for (Monad Ptr)
    arising from a do statement
  Possible fix: add an instance declaration for (Monad Ptr) …
Run Code Online (Sandbox Code Playgroud)

haskell

1
推荐指数
1
解决办法
530
查看次数

标签 统计

haskell ×2

io ×1

output ×1

string ×1