私があなたを助けてくれることを願っています。私は何年もの命令的言語の後にハスケルのノブですので、もし私がばかな間違いをしているなら、それを説明して、私は学ぶことができます。私は、データベースクエリの結果から、この型のインスタンスを構築IO Monadでレコードの更新に失敗しましたか?
data DicomSopInstance = DicomSopInstance {
sopInstancePath :: String,
sopInstanceUid :: String,
sopInstancePk :: Int64,
seriesFk :: Int64,
sopInstanceFrameCount :: Int32,
sourceDicom :: Maybe EncapDicomObject
}
:
は、私は次のデータ型を持っています。結果がsourceDicomフィールドに来るとき、私はそれをMaybe値にしたので、何の値も持てません。問題は、EncapDicomObjectをロードして結果のデータ型を更新しようとするときに発生します。そのため、アクセスするたびにEncapDicomObjectをディスクからロードする必要はありません。
次は、この問題を引き起こすコードです。私の意図は、EncapDicomObjectが読み込まれているかどうか、既存の(Just)値を使用するかどうか(Nothingが検出されていない場合)を読み込み、NothingをJustに変更するかどうかをテストすることです。私はマークされた行をコメントアウトした場合面倒ラインが「**」
showImage :: TextCtrl t -> DicomImage -> IO()
showImage textCtl image = do
let sopInst = sopInstance image
let maybeEncapDicom = sourceDicom sopInst
case maybeEncapDicom of
Just encapDicom -> do
showEncapDicomObject textCtl encapDicom (sopInstancePath sopInst)
return()
Nothing -> do
eitherDicom <- readDicomFile $ sopInstancePath sopInst
case eitherDicom of
Left errorMessage -> do
infoM "Hastur" $ "Error reading DICOM file: " ++
(sopInstancePath sopInst) ++ " - " ++ errorMessage
textCtrlSetValue textCtl $ "*** DICOM: " ++
(sopInstancePath sopInst) ++ " ***\n"
textCtrlAppendText textCtl errorMessage
textCtrlAppendText textCtl "\n*** [End] ***"
textCtrlShowPosition textCtl 0
return()
Right encapDicom -> do
sopInst { sourceDicom = Just encapDicom } -- ****
showEncapDicomObject textCtl encapDicom (sopInstancePath sopInst)
return()
でマークされ、その後のコードはコンパイルが、それは常に何に遭遇しないので、それは毎回ファイルをロードします。持っている)(私はSTMTがsopInstを更新し、IOを返すように関数を作成する代わりに、IO()しかし、すべての私の試みのDicomSopInstanceを返すという意味として解釈
src\Hastur.hs:382:10:
Couldn't match expected type `IO a'
against inferred type `DicomSopInstance'
In a stmt of a 'do' expression:<br>
sopInst {sourceDicom = Just encapDicom}
:私はコメントを解除した場合、私は次のエラーを取得します失敗しました。
私には何が欠けていますか? Haskellの非厳密な動作が私のためにやるか、あるいは単に間違った設計をしたときに、オンデマンドの負荷をかけようとしていますか?変更可能な変数にsourceDicomを変換する私の試みは、同様に無駄になってきた:(
歓声
ジェームズ
将来は、コードを4つのスペースでインデントしてください。コードボタン(1と1が付いたコードボタン)を使用すると、コードの形式が正しく設定されます。 – sepp2k
Ack :(AdBlockは私からインターフェイスの多くを隠していた)固定された私は願っています –