From travis.cardwell at extrema.is Wed Mar 1 09:59:02 2023 From: travis.cardwell at extrema.is (Travis Cardwell) Date: Wed, 1 Mar 2023 18:59:02 +0900 Subject: [Haskell-beginners] Understanding reason for Monad In-Reply-To: References: Message-ID: Hi Pietro, On Tue, Feb 28, 2023 at 11:01 PM Pietro Grandinetti wrote: > Thank you very much. I have a question about the `putLanguage` > function below. You are welcome! putLanguage :: (MonadIO m, MonadLocale m) => m () putLanguage = do locale <- askLocale liftIO . putStrLn $ case locale of En -> "English" It -> "Italiano" > I understand that the result type, in this case > `MonadLocale m => m ()`, determines in what context the function > `askLocale` is resolved. Correct. This function runs in monad `m`: it runs in any monad with both `MonadIO` and `MonadLocale` instances, returning `()` (pronounced "unit"). Function `askLocale` can be used here because the monad has a `MonadLocale` instance. > But what would happen if the function type was putLanguage' :: (MonadOut m, MonadIn v) => v () -> m () putLanguage' = do locale <- askLocale ... > which `askLocale` function would be used? This function runs in monad `m`: it runs in any monad with a `MonadOut` instance, returning `()`. Function `askLocale` cannot be used here because there is no `MonadLocale m` constraint. To answer the gist of your question, however, the functions available to use are determined by the `m` monad, *not* `v`. In this function, `v ()` is a function that is passed as an argument. Such a monadic argument is generally called an "action." You can execute that action if you can create the appropriate monadic context. In this case, there is no `MonadIn m` constraint, so it is not possible to execute the action within `putLanguage'` (given just the above information). Here is a minimal example: module Main (main) where -- https://hackage.haskell.org/package/base import Control.Monad.IO.Class (MonadIO(liftIO)) actionDemo :: MonadIO m => (String -> IO ()) -> m () actionDemo trace = liftIO $ trace "Hello!" main :: IO () main = actionDemo putStrLn Function `actionDemo` runs in monad `m`: it runs in any monad with a `MonadIO` instance, returning `()`. It accepts argument `trace`, which is an action that accepts a `String` argument, runs in the `IO` monad, and returns `()`. The `main` function passes `putStrLn`, which has this type. Since `actionDemo` runs in monad `m`, it cannot execute an action in the `IO` monad directly. `MonadIO` provides a `liftIO` function to execute actions in the `IO` monad, however, so `liftIO` is used here to execute `trace` in the `IO` monad. Cheers, Travis From pietro.gra at hotmail.it Sat Mar 4 14:43:06 2023 From: pietro.gra at hotmail.it (Pietro Grandinetti) Date: Sat, 4 Mar 2023 14:43:06 +0000 Subject: [Haskell-beginners] Show encoded string of JWT / Crypto.JWT Message-ID: Hello- I am working with this package: I created a `SignedJWT` object, but cannot find a way to print it in the standard string form. I mean the string that would be used by clients, for example to send it in the "Authorization: Bearer ..." header of a HTTP request. Like this one: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" ghci> jwt <- ... -- some code ghci> :t jwt jwt :: Either JWTError SignedJWT ghci> show jwt "Right JWS Base64Octets \"{\\\"aud\\\":\\\"bob\\\",\\\"iat\\\":1.677940566501089259e9,\\\"iss\\\":\\\"alice\\\"}\" Identity (Signature Nothing (JWSHeader {_jwsHeaderAlg = HeaderParam () PS512, _jwsHeaderJku = Nothing, _jwsHeaderJwk = Nothing, _jwsHeaderKid = Nothing, _jwsHeaderX5u = Nothing, _jwsHeaderX5c = Nothing, _jwsHeaderX5t = Nothing, _jwsHeaderX5tS256 = Nothing, _jwsHeaderTyp = Nothing, _jwsHeaderCty = Nothing, _jwsHeaderCrit = Nothing}) (Base64Octets \"\\DC2\\DC4\\151`\\131\\229j\\SI,\\178-\\CAN\\191UV-\\191u\\160\\217\\NAK\\247a\\150\\159\\195\\141=\\176\\212\\197\\209\\&8u+\\SIn\\DLE]\\167\\153\\SO\\142t\\163^\\EMW\\NAKt\\252\\b\\142j\\209^\\169j\\180 /U*^\\184\\t\\ESC\\DC4:\\DC4\\191\\150\\150\\192\\145\\FS\\172W!\\197\\190\\193\\RSx\\216\\244\\188\\168\\141\\213|\\EM\\174\\219\\230\\130b\\157\\130:\\b)\\n\\158\\169\\228?\\179\\177\\188\\234[N3\\ETX\\162\\230C\\167\\130V'V\\246\\240\\193\\243@\\SYN\\GS\\228\\157\\248\\161{\\131\\204=fI\\SYN\\GSZ\\149\\&8\\139\\a\\153\\a3\\nt\\185\\222\\&4\\FS\\EM\\171\\NUL2\\GS\\211,8CE(\\230\\240j\\150\\253\\204\\255\\188\\141\\250-:\\ESCx;3\\163K7\\137>\\145\\&0\\186\\194U0;\\b\\206\\221)C\\SOHX\\233?\\160\\168VqY\\160\\218\\&1\\224v\\f\\215[\\n\\231\\243a>\\212\\241\\237b\\138\\251eb\\207\\217\\t\\NUL\\138\\DC3\\184\\142I\\132\\154\\213\\139\\171\\137\\214\\ETX\\250\\198xn\\GS\\137\\182\\161b\\183\\f\\195\\231(\\202\\196\\177\\SI\\222\\193\\245Dv\\199\\156\\239D\\181.\\189\\153\\EOT\\SUB\\158\\160x\\135\\169$\\226\\DC3\\132\\198\\204$\\229\\&2ZTaG\\168\\203\\188\\v\\250\\SI\\214\\176;xkx\\170C\\DLE\\228\\NULc\\200r-\\205z\\243\\246\\NUL\\212Qx\\DLE!\\182\\188^\\STX\\244@\\252\\SI\\253_L\\165\\128g\\136\\197\\NUL\\201Cb\\vm\\238_>}F6\\193[As\\v\\222\\209\\146\\206\\215\\174\\&9\\NAK`E\\253\\199\\237\\236'\\149o9\\141\\130\\138\\DEL;\\NAK\\ESC\\225\\189\\170\\&1\\SUB\\CAN\\178U\\ETBL\\216G\\251\\218\\137\\191\\SYN\\193(\\DC4q\\196T\\174>@y\\198\\&4R\\138\\155~H\\DEL\\135\\202\\236\\&0\\219\\136r\\ETX\\138\\174js\\192^\\238\\193L\\204|x\\170\\140B\\158\\f\\164>2\\166\\156*W\\\\\\130\\160*\\230a\\DC3\\173m'\\DELm\\FSS[?6\\206\\170\\ESC\\145MKS=\\164Ec0\\EM\\177\\&4whq\\194\\ACKM\\147\\210\\183\\228\\161\\136\\162{\\166\\226\\174g\\241\\210\\223b\\190\\&5\\229\\212\"))" -------------- next part -------------- An HTML attachment was scrubbed... URL: From pietro.gra at hotmail.it Sat Mar 4 14:46:13 2023 From: pietro.gra at hotmail.it (Pietro Grandinetti) Date: Sat, 4 Mar 2023 14:46:13 +0000 Subject: [Haskell-beginners] Show encoded string of JWT / Crypto.JWT In-Reply-To: References: Message-ID: Apologies, forgot to link the package: https://hackage.haskell.org/package/jose-0.10/docs/Crypto-JWT.html#t:SignedJWT ________________________________ From: Beginners on behalf of Pietro Grandinetti Sent: Saturday, March 4, 2023 3:43 PM To: beginners at haskell.org Subject: [Haskell-beginners] Show encoded string of JWT / Crypto.JWT Hello- I am working with this package: I created a `SignedJWT` object, but cannot find a way to print it in the standard string form. I mean the string that would be used by clients, for example to send it in the "Authorization: Bearer ..." header of a HTTP request. Like this one: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" ghci> jwt <- ... -- some code ghci> :t jwt jwt :: Either JWTError SignedJWT ghci> show jwt "Right JWS Base64Octets \"{\\\"aud\\\":\\\"bob\\\",\\\"iat\\\":1.677940566501089259e9,\\\"iss\\\":\\\"alice\\\"}\" Identity (Signature Nothing (JWSHeader {_jwsHeaderAlg = HeaderParam () PS512, _jwsHeaderJku = Nothing, _jwsHeaderJwk = Nothing, _jwsHeaderKid = Nothing, _jwsHeaderX5u = Nothing, _jwsHeaderX5c = Nothing, _jwsHeaderX5t = Nothing, _jwsHeaderX5tS256 = Nothing, _jwsHeaderTyp = Nothing, _jwsHeaderCty = Nothing, _jwsHeaderCrit = Nothing}) (Base64Octets \"\\DC2\\DC4\\151`\\131\\229j\\SI,\\178-\\CAN\\191UV-\\191u\\160\\217\\NAK\\247a\\150\\159\\195\\141=\\176\\212\\197\\209\\&8u+\\SIn\\DLE]\\167\\153\\SO\\142t\\163^\\EMW\\NAKt\\252\\b\\142j\\209^\\169j\\180 /U*^\\184\\t\\ESC\\DC4:\\DC4\\191\\150\\150\\192\\145\\FS\\172W!\\197\\190\\193\\RSx\\216\\244\\188\\168\\141\\213|\\EM\\174\\219\\230\\130b\\157\\130:\\b)\\n\\158\\169\\228?\\179\\177\\188\\234[N3\\ETX\\162\\230C\\167\\130V'V\\246\\240\\193\\243@\\SYN\\GS\\228\\157\\248\\161{\\131\\204=fI\\SYN\\GSZ\\149\\&8\\139\\a\\153\\a3\\nt\\185\\222\\&4\\FS\\EM\\171\\NUL2\\GS\\211,8CE(\\230\\240j\\150\\253\\204\\255\\188\\141\\250-:\\ESCx;3\\163K7\\137>\\145\\&0\\186\\194U0;\\b\\206\\221)C\\SOHX\\233?\\160\\168VqY\\160\\218\\&1\\224v\\f\\215[\\n\\231\\243a>\\212\\241\\237b\\138\\251eb\\207\\217\\t\\NUL\\138\\DC3\\184\\142I\\132\\154\\213\\139\\171\\137\\214\\ETX\\250\\198xn\\GS\\137\\182\\161b\\183\\f\\195\\231(\\202\\196\\177\\SI\\222\\193\\245Dv\\199\\156\\239D\\181.\\189\\153\\EOT\\SUB\\158\\160x\\135\\169$\\226\\DC3\\132\\198\\204$\\229\\&2ZTaG\\168\\203\\188\\v\\250\\SI\\214\\176;xkx\\170C\\DLE\\228\\NULc\\200r-\\205z\\243\\246\\NUL\\212Qx\\DLE!\\182\\188^\\STX\\244@\\252\\SI\\253_L\\165\\128g\\136\\197\\NUL\\201Cb\\vm\\238_>}F6\\193[As\\v\\222\\209\\146\\206\\215\\174\\&9\\NAK`E\\253\\199\\237\\236'\\149o9\\141\\130\\138\\DEL;\\NAK\\ESC\\225\\189\\170\\&1\\SUB\\CAN\\178U\\ETBL\\216G\\251\\218\\137\\191\\SYN\\193(\\DC4q\\196T\\174>@y\\198\\&4R\\138\\155~H\\DEL\\135\\202\\236\\&0\\219\\136r\\ETX\\138\\174js\\192^\\238\\193L\\204|x\\170\\140B\\158\\f\\164>2\\166\\156*W\\\\\\130\\160*\\230a\\DC3\\173m'\\DELm\\FSS[?6\\206\\170\\ESC\\145MKS=\\164Ec0\\EM\\177\\&4whq\\194\\ACKM\\147\\210\\183\\228\\161\\136\\162{\\166\\226\\174g\\241\\210\\223b\\190\\&5\\229\\212\"))" -------------- next part -------------- An HTML attachment was scrubbed... URL: