programacao-funcional | discipline Special Topics | Functional Programming library
kandi X-RAY | programacao-funcional Summary
kandi X-RAY | programacao-funcional Summary
Repository for the discipline Special Topics in Programming: Functional Programming
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of programacao-funcional
programacao-funcional Key Features
programacao-funcional Examples and Code Snippets
Community Discussions
Trending Discussions on programacao-funcional
QUESTION
I'm trying to build a simple blog using Haskell and the Framework Scotty. Using a Model.hs I have:
...ANSWER
Answered 2018-Jul-05 at 19:38In Haskell, all functions are pure---so something like selectPosts
, which needs to go out and do IO to talk to a database, can't just do that and return the value from the database. Instead, these kinds of functions return something of type IO a
, which you can think of as basically a description of how to go out and do IO to get a value of type a
. These "IO actions" can be composed together, and one of them can be assigned to main
; at runtime, the RTS will execute these IO actions.
However, you aren't composing the IO a
value that you get back from selectPosts
to be part of the larger IO
value that eventually becomes main
; you are trying to directly use it by feeding it into json
. This won't work, because there's no (good/easy) way to convert a description of how to do IO into a JSON string.
The way that Haskell deals with composing these values is through an abstraction known as a "monad", which is useful in a lot of other cases as well. do
notation can be used to write this monadic sequencing in a very natural style. You can't just write posts <- withTestConnection S.selectPosts
here because Scotty's get
function takes a value of the monadic ActionM
type, not IO
. However, it turns out that ActionM
is basically a bunch of other useful stuff layered on top of IO
, so it should be possible to "lift" the IO action from selectPosts
into Scotty's ActionM
monad:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install programacao-funcional
Elm packages are available at elm-lang.org. If you are going to make HTTP requests, you may need elm/http and elm/json. You can get them set up in your project with the following commands: elm install elm/http and elm install elm/json. It adds these dependencies into your elm.json file, making these packages available in your project. Please refer guide.elm-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page