我已经过滤了[也许是文本]类型以从列表中删除Nothing,现在我想将结果放入[文本]类型,但是编译器抱怨类型不兼容:
(bd_rows_WDS :: [Only (Maybe Text)]) <- query conn qry_head_WDS (Only (name::String))
-- remove the records having N°BD NULL
let fltWDS :: [Only Text] = Prelude.filter (\(Only a) ->
case a of
Nothing -> False
Just a -> True)
bd_rows_WDS
Prelude> :load UpdateSidonie
[1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted )
UpdateSidonie.hs:282:33: error:
• Couldn't match type ‘Maybe Text’ with ‘Text’
Expected type: [Only Text]
Actual type: [Only (Maybe Text)]
• In the expression:
Prelude.filter
(\ (Only a)
-> case a of
Nothing -> False
Just a -> True)
bd_rows_WDS
In a pattern binding:
fltWDS :: [Only Text]
= Prelude.filter
(\ (Only a)
-> case a of
Nothing -> False
Just a -> True)
bd_rows_WDS
In the expression:
do conn <- connect
defaultConnectInfo
{connectHost = "moita", connectUser = "mattei",
connectPassword = "sidonie2", connectDatabase = "sidonie"}
(rows :: [(Text, Double)]) <- query_
conn
"SELECT Nom,distance FROM AngularDistance WHERE distance > 0.000278"
(names :: [Only Text]) <- query_
conn
"SELECT Nom FROM AngularDistance WHERE distance > 0.000278"
let resLstNames = Prelude.map fromOnly names
....
|
282 | let fltWDS :: [Only Text] = Prelude.filter (\(Only a) ->
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
Failed, no modules loaded.
如何确定id进行类型转换,现在我确定没有更多的值了?
答案 0 :(得分:6)
您可以使用catMaybes
中的Data.Maybe
。
catMaybes :: [Maybe a] -> [a]
PS:它还过滤掉Nothing
,所以您不需要自己做。