yesod

What typeclasses need to be defined for a Yesod path?

左心房为你撑大大i 提交于 2019-12-06 11:16:02
问题 In my application, my data model has several different instances of using an Integer or a String for some identifier. For safety, I've gone ahead and wrapped those identifiers into newtype declarations like so: newtype DocId = DocId Integer newtype GroupName = GroupName String newtype UserName = UserName String When I'm setting up my Yesod paths, I'm discovering that I have to create at least three instances for each of these, and the instances are almost always identical instance Read DocId

Getting “Could not find module `Yesod'” when I try to run first example from Yesod book

北城余情 提交于 2019-12-06 10:47:26
I know this seems a duplicate to Could not find module `Yesod' , but unlike that user, ghc-pkg list does not show Yesod in its output on my computer, they didn't seem to be using stack (I am, and I'm not sure if that means I don't need to worry about ghc-pkg list ), and additionally, the answer (code) to that question did not help my situation. The Yesod Book has an example that I've been trying to get to work for several hours now. I'll reprint it here {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} import Yesod

Where to add 'always running' thread to Yesod applications

非 Y 不嫁゛ 提交于 2019-12-06 09:16:23
I'm writing a Yesod application, but it also needs to fork several non-web services. (UDP listeners, TCP listening port, etc.) Where is the correct place to splice in a fork, such that this work seamlessly, regardless of whether my app is running in 'yesod devel' or deployed for production. P.S. I really just want to add a pseudo-Main, which will be forked (at service start) by whichever webserver runs the app through WAI. You should put it in the makeApplication function in the scaffolded Application.hs file. This function will run once for every instance of your web application that is

Run Keter without GHC and cabal

不羁岁月 提交于 2019-12-06 07:52:54
I have a server and want to deploy my Yesod applications without installing GHC and Cabal. I am not sure if is possible: a Teacher told me that I must first compile Keter in my machine and, after that, put keter executable on the server, though I am not sure how to do that. To build Keter, first you'll need to clone the sources from its GitHub repository . Then you'll need to set up a Haskell build environment and use cabal build or cabal install to build the sources. Personally, I use a Docker container derived from an image based on the following Dockerfile : FROM haskell:7.10.2 RUN apt-get

Foreign key constraints in Yesod/Persistent?

前提是你 提交于 2019-12-06 07:32:42
问题 I am trying to use Database.Persistant to make a database for a Scotty app, and I cannot figure out the syntax for adding a foreign key constraint between tables. For example, I have a User table and a Post table, and I want the Post table to have an attribute authorId which references UserId in User . This can be accomplished quite easily in raw SQL, but I want to be able to access the data through haskell without resorting to raw sql commands. Also, the constraints would be overwritting

Trying to send an email in yesod using hamlet

柔情痞子 提交于 2019-12-06 03:41:06
I am building a survey site in Yesod (0.10) and am getting lost in the types. Here is a simplified version on what I am trying to do. invitation url = do render <- getUrlRender return $ renderHtml [hamlet| <p>Dear foo, please take our <a href=@{ShowSurveyR url}>survey. |] render Another function is going to call this in hopes of getting something that can be passed to simpleMail from Network.Mail.Mime. The above function gives a type error: Handler/Root.hs:404:13: The function `renderHtml' is applied to two arguments, but its type `Html -> LT.Text' has only one This is confusing, because the

How do I use wai-handler-devel with a simple wai application

放肆的年华 提交于 2019-12-06 03:22:10
问题 I have the basic "hello world" application setup using wai, and would like to use wai-handler-devel, but am unsure how to go about it and can't find any examples of it in usage on a wai project. {-# LANGUAGE OverloadedStrings #-} import Network.Wai import Network.HTTP.Types import Network.Wai.Handler.Warp (run) import Data.ByteString.Lazy.Char8 () -- Just for an orphan instance app :: Application app _ = return $ responseLBS status200 [("Content-Type", "text/plain")] "Hello, World!" main ::

How can I include an hamletfile inside another using widgetFile?

自古美人都是妖i 提交于 2019-12-05 18:51:32
For reusability, I want to re-use a widget inside another. For instance, the widget file blogpost.hamlet could contain how a post is displayed, and blog.hamlet could contain the full blog. The following content of blog.hamlet does not work: $forall post <- posts ^{widgetFile "blogpost") So, what is the correct syntax to embed one widget inside another? The Hamlet syntax does not support embedding Template Haskell splices inside of it, which makes the code you're looking to do impossible. Instead, you need to create a helper function in Haskell, e.g.: blogpost post = $(widgetFile "blogpost")

Haskell Persistent: how get entity from db by key if i have key in integer variable?

狂风中的少年 提交于 2019-12-05 17:31:55
问题 I use Persistent orm with scotty web framework. I want to get value from db by id. These id are coming to me from GET request There are "get" function that takes "Key Entity" variable and returns "Maybe Entity". I use following code to get value from db k <- keyFromValues $ [(PersistInt64 myOwnIntVarFromRequest)] case k of Left _ -> {-some processing-} Right x -> do t <- liftIO . runDb $ get (x::Key Post) --Post is one of my models case t of Nothing -> {-processing-} Just x -> {-processing-}

How can I post FileInfo to a web service using Yesod and Http-Conduit?

风格不统一 提交于 2019-12-05 17:27:04
I am working with the default Yesod scaffolding project. I have created a page that displays a simple form to upload files. (The form will likely be created on the client using Javascript.) For brevity, the form has a single file input: <form method="post" action=@{UploadR}> <input type="file" name="myfile"> <button type="submit"> My objective is to process the form data and then upload the file to a web service. I have no trouble processing the form, my concern is interacting with the web service. For example, given the following Yesod handler: postUploadR :: Handler Html postUploadR = do mgr