Haskell transfer between monadic functions





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1















Feel I am never going to fully grasp Haskell now. Two functions: one that counts records in a SQlite DB, so it can produce incremental IDs (checkUniqueID). The other one to make the records, calling on checkUniqueID. I just need the value over to taskEntry as an Int. I guess I am missing the knowledge to stay in the monadic realm. Code below.



-- checkUniqueID :: IO ()
checkUniqueID = do
conn <- open "taglist.db"
len <- query_ conn "SELECT (id) FROM task" :: IO [Only Int]
let showLength = Data.List.length $ len
close conn
return (showLength + 1) -- for testing purposes

-- fieldnames: id, task, date_in, date_out
taskEntry :: IO ()
taskEntry = do
putStrLn "Provide task and date due: "
let taskIDInt = checkUniqueID -- issue here!
task <- getLine
date_out <- getLine
let date_in = "today"
conn <- open "taglist.db"
execute conn "INSERT INTO task (id, task, date_in, date_out) VALUES (?,?,?,?)"
(taskIDInt :: Int , task :: String , date_in :: String , date_out :: String)
close conn
return ()









share|improve this question


















  • 3





    for starters, the type should probably be checkUniqueID :: IO Int - you actually want to return something of type Int, besides executing an IO action. Then: taskIDInt <- checkUniqueID, because checkUniqueID is in IO.

    – mb21
    Nov 23 '18 at 16:04


















-1















Feel I am never going to fully grasp Haskell now. Two functions: one that counts records in a SQlite DB, so it can produce incremental IDs (checkUniqueID). The other one to make the records, calling on checkUniqueID. I just need the value over to taskEntry as an Int. I guess I am missing the knowledge to stay in the monadic realm. Code below.



-- checkUniqueID :: IO ()
checkUniqueID = do
conn <- open "taglist.db"
len <- query_ conn "SELECT (id) FROM task" :: IO [Only Int]
let showLength = Data.List.length $ len
close conn
return (showLength + 1) -- for testing purposes

-- fieldnames: id, task, date_in, date_out
taskEntry :: IO ()
taskEntry = do
putStrLn "Provide task and date due: "
let taskIDInt = checkUniqueID -- issue here!
task <- getLine
date_out <- getLine
let date_in = "today"
conn <- open "taglist.db"
execute conn "INSERT INTO task (id, task, date_in, date_out) VALUES (?,?,?,?)"
(taskIDInt :: Int , task :: String , date_in :: String , date_out :: String)
close conn
return ()









share|improve this question


















  • 3





    for starters, the type should probably be checkUniqueID :: IO Int - you actually want to return something of type Int, besides executing an IO action. Then: taskIDInt <- checkUniqueID, because checkUniqueID is in IO.

    – mb21
    Nov 23 '18 at 16:04














-1












-1








-1








Feel I am never going to fully grasp Haskell now. Two functions: one that counts records in a SQlite DB, so it can produce incremental IDs (checkUniqueID). The other one to make the records, calling on checkUniqueID. I just need the value over to taskEntry as an Int. I guess I am missing the knowledge to stay in the monadic realm. Code below.



-- checkUniqueID :: IO ()
checkUniqueID = do
conn <- open "taglist.db"
len <- query_ conn "SELECT (id) FROM task" :: IO [Only Int]
let showLength = Data.List.length $ len
close conn
return (showLength + 1) -- for testing purposes

-- fieldnames: id, task, date_in, date_out
taskEntry :: IO ()
taskEntry = do
putStrLn "Provide task and date due: "
let taskIDInt = checkUniqueID -- issue here!
task <- getLine
date_out <- getLine
let date_in = "today"
conn <- open "taglist.db"
execute conn "INSERT INTO task (id, task, date_in, date_out) VALUES (?,?,?,?)"
(taskIDInt :: Int , task :: String , date_in :: String , date_out :: String)
close conn
return ()









share|improve this question














Feel I am never going to fully grasp Haskell now. Two functions: one that counts records in a SQlite DB, so it can produce incremental IDs (checkUniqueID). The other one to make the records, calling on checkUniqueID. I just need the value over to taskEntry as an Int. I guess I am missing the knowledge to stay in the monadic realm. Code below.



-- checkUniqueID :: IO ()
checkUniqueID = do
conn <- open "taglist.db"
len <- query_ conn "SELECT (id) FROM task" :: IO [Only Int]
let showLength = Data.List.length $ len
close conn
return (showLength + 1) -- for testing purposes

-- fieldnames: id, task, date_in, date_out
taskEntry :: IO ()
taskEntry = do
putStrLn "Provide task and date due: "
let taskIDInt = checkUniqueID -- issue here!
task <- getLine
date_out <- getLine
let date_in = "today"
conn <- open "taglist.db"
execute conn "INSERT INTO task (id, task, date_in, date_out) VALUES (?,?,?,?)"
(taskIDInt :: Int , task :: String , date_in :: String , date_out :: String)
close conn
return ()






sqlite haskell io monads






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 16:00









MadderoteMadderote

352211




352211








  • 3





    for starters, the type should probably be checkUniqueID :: IO Int - you actually want to return something of type Int, besides executing an IO action. Then: taskIDInt <- checkUniqueID, because checkUniqueID is in IO.

    – mb21
    Nov 23 '18 at 16:04














  • 3





    for starters, the type should probably be checkUniqueID :: IO Int - you actually want to return something of type Int, besides executing an IO action. Then: taskIDInt <- checkUniqueID, because checkUniqueID is in IO.

    – mb21
    Nov 23 '18 at 16:04








3




3





for starters, the type should probably be checkUniqueID :: IO Int - you actually want to return something of type Int, besides executing an IO action. Then: taskIDInt <- checkUniqueID, because checkUniqueID is in IO.

– mb21
Nov 23 '18 at 16:04





for starters, the type should probably be checkUniqueID :: IO Int - you actually want to return something of type Int, besides executing an IO action. Then: taskIDInt <- checkUniqueID, because checkUniqueID is in IO.

– mb21
Nov 23 '18 at 16:04












1 Answer
1






active

oldest

votes


















2














First, checkUniqueID returns an Int, so its type should be IO Int, not IO ():



checkUniqueID :: IO Int


Second, within the do notation, the left arrow <- is what binds result of a monadic function to a name. You're already using it with getLine, so I'm not entirely sure why you would fail to use it with checkUniqueID as well:



taskIDInt <- checkUniqueID





share|improve this answer
























  • I am not failing with your suggestion. I have a hard time seeing the forrest through the trees. You put me on the right track and it works! Sorry for this... Sometimes I feel a bit stupid trying monoids, applicatives, functors etc while the only thing I need to do is a simple bind of two monadic functions! Thanks

    – Madderote
    Nov 23 '18 at 19:02












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449748%2fhaskell-transfer-between-monadic-functions%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














First, checkUniqueID returns an Int, so its type should be IO Int, not IO ():



checkUniqueID :: IO Int


Second, within the do notation, the left arrow <- is what binds result of a monadic function to a name. You're already using it with getLine, so I'm not entirely sure why you would fail to use it with checkUniqueID as well:



taskIDInt <- checkUniqueID





share|improve this answer
























  • I am not failing with your suggestion. I have a hard time seeing the forrest through the trees. You put me on the right track and it works! Sorry for this... Sometimes I feel a bit stupid trying monoids, applicatives, functors etc while the only thing I need to do is a simple bind of two monadic functions! Thanks

    – Madderote
    Nov 23 '18 at 19:02
















2














First, checkUniqueID returns an Int, so its type should be IO Int, not IO ():



checkUniqueID :: IO Int


Second, within the do notation, the left arrow <- is what binds result of a monadic function to a name. You're already using it with getLine, so I'm not entirely sure why you would fail to use it with checkUniqueID as well:



taskIDInt <- checkUniqueID





share|improve this answer
























  • I am not failing with your suggestion. I have a hard time seeing the forrest through the trees. You put me on the right track and it works! Sorry for this... Sometimes I feel a bit stupid trying monoids, applicatives, functors etc while the only thing I need to do is a simple bind of two monadic functions! Thanks

    – Madderote
    Nov 23 '18 at 19:02














2












2








2







First, checkUniqueID returns an Int, so its type should be IO Int, not IO ():



checkUniqueID :: IO Int


Second, within the do notation, the left arrow <- is what binds result of a monadic function to a name. You're already using it with getLine, so I'm not entirely sure why you would fail to use it with checkUniqueID as well:



taskIDInt <- checkUniqueID





share|improve this answer













First, checkUniqueID returns an Int, so its type should be IO Int, not IO ():



checkUniqueID :: IO Int


Second, within the do notation, the left arrow <- is what binds result of a monadic function to a name. You're already using it with getLine, so I'm not entirely sure why you would fail to use it with checkUniqueID as well:



taskIDInt <- checkUniqueID






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 16:20









Fyodor SoikinFyodor Soikin

43.8k569102




43.8k569102













  • I am not failing with your suggestion. I have a hard time seeing the forrest through the trees. You put me on the right track and it works! Sorry for this... Sometimes I feel a bit stupid trying monoids, applicatives, functors etc while the only thing I need to do is a simple bind of two monadic functions! Thanks

    – Madderote
    Nov 23 '18 at 19:02



















  • I am not failing with your suggestion. I have a hard time seeing the forrest through the trees. You put me on the right track and it works! Sorry for this... Sometimes I feel a bit stupid trying monoids, applicatives, functors etc while the only thing I need to do is a simple bind of two monadic functions! Thanks

    – Madderote
    Nov 23 '18 at 19:02

















I am not failing with your suggestion. I have a hard time seeing the forrest through the trees. You put me on the right track and it works! Sorry for this... Sometimes I feel a bit stupid trying monoids, applicatives, functors etc while the only thing I need to do is a simple bind of two monadic functions! Thanks

– Madderote
Nov 23 '18 at 19:02





I am not failing with your suggestion. I have a hard time seeing the forrest through the trees. You put me on the right track and it works! Sorry for this... Sometimes I feel a bit stupid trying monoids, applicatives, functors etc while the only thing I need to do is a simple bind of two monadic functions! Thanks

– Madderote
Nov 23 '18 at 19:02




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449748%2fhaskell-transfer-between-monadic-functions%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy