From dennis.raddle at gmail.com Mon Aug 1 08:06:05 2016 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Mon, 1 Aug 2016 01:06:05 -0700 Subject: [Haskell-beginners] reading lines with history from bash terminal in OS X In-Reply-To: References: Message-ID: I'm looking over haskeline. It looks like I have to modify some of my code that is in the IO monad right now. I use 'evaluate' in several places, and also 'evaluate $ force', to make sure that IO exceptions are encountered where I can catch them. Can I use 'evaluate' with InputT? I'm muddled headed about what to do. I guess I would lift 'evaluate' into the inner monad? I am not sure what those words mean. How would I catch IO exceptions? On Thu, Jul 28, 2016 at 5:35 PM, Dennis Raddle wrote: > Thanks. I'll install haskeline > > On Thu, Jul 28, 2016 at 5:05 PM, David McBride wrote: > >> You will have to use the haskeline library. FYI that is the library that >> makes ghci work. >> >> On Thu, Jul 28, 2016 at 6:09 PM, Dennis Raddle >> wrote: >> >>> I wrote a program first in Windows, where it works as expected, and now >>> I'm using it in OS X and getting undesired behavior. >>> >>> It reads lines from the terminal using the getLine function. In Windows >>> (DOS, actually) the up and down arrows can be used to choose previously >>> entered lines. However, this does not work in bash in OS X. >>> >>> What do I need to get the history available via the arrow keys? >>> >>> D >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Mon Aug 1 12:43:14 2016 From: toad3k at gmail.com (David McBride) Date: Mon, 1 Aug 2016 08:43:14 -0400 Subject: [Haskell-beginners] reading lines with history from bash terminal in OS X In-Reply-To: References: Message-ID: MonadIO m => MonadIO (InputT m) MonadException m => MonadException (InputT m) MonadIO means you have access to liftIO. liftIO . evaluate . force $ mycode. MonadException means that you have access to haskeline's exception catching mechanisms. In System.Console.Haskeline.MonadException, you have the catch, catches, and handle functions which will allow you to catch IO exceptions (in combination with liftIO), and also a bracket which will just let you do arbitrary IO actions and clean up when you are done (or hit an exception). >let mycode = undefined :: Handle -> IO () -- example code runInputT _ (bracket (liftIO $ openFile "blah" ReadMode) (liftIO . hClose) (\fp -> liftIO . mycode $ fp)) Another way to use it might be runInputT _ (liftIO $ mycode _) `catches` [Handler iohandler, Handler anotherhandler] where iohandler :: IOException -> IO () iohandler e = putStrLn "got io exception" >> return () Exceptions are always a pain, and so are transformers, but you get used to them. On Mon, Aug 1, 2016 at 4:06 AM, Dennis Raddle wrote: > I'm looking over haskeline. It looks like I have to modify some of my code > that is in the IO monad right now. I use 'evaluate' in several places, and > also 'evaluate $ force', to make sure that IO exceptions are encountered > where I can catch them. Can I use 'evaluate' with InputT? I'm muddled > headed about what to do. I guess I would lift 'evaluate' into the inner > monad? I am not sure what those words mean. How would I catch IO exceptions? > > On Thu, Jul 28, 2016 at 5:35 PM, Dennis Raddle > wrote: > >> Thanks. I'll install haskeline >> >> On Thu, Jul 28, 2016 at 5:05 PM, David McBride wrote: >> >>> You will have to use the haskeline library. FYI that is the library >>> that makes ghci work. >>> >>> On Thu, Jul 28, 2016 at 6:09 PM, Dennis Raddle >>> wrote: >>> >>>> I wrote a program first in Windows, where it works as expected, and now >>>> I'm using it in OS X and getting undesired behavior. >>>> >>>> It reads lines from the terminal using the getLine function. In Windows >>>> (DOS, actually) the up and down arrows can be used to choose previously >>>> entered lines. However, this does not work in bash in OS X. >>>> >>>> What do I need to get the history available via the arrow keys? >>>> >>>> D >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Tue Aug 2 19:24:31 2016 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Tue, 2 Aug 2016 12:24:31 -0700 Subject: [Haskell-beginners] reading lines with history from bash terminal in OS X In-Reply-To: References: Message-ID: Thanks. I will study this. On Mon, Aug 1, 2016 at 5:43 AM, David McBride wrote: > MonadIO m => MonadIO (InputT m) > MonadException m => MonadException (InputT m) > > MonadIO means you have access to liftIO. liftIO . evaluate . force $ > mycode. > MonadException means that you have access to haskeline's exception > catching mechanisms. > > In System.Console.Haskeline.MonadException, you have the catch, catches, > and handle functions which will allow you to catch IO exceptions (in > combination with liftIO), and also a bracket which will just let you do > arbitrary IO actions and clean up when you are done (or hit an exception). > > >let mycode = undefined :: Handle -> IO () -- example code > > runInputT _ (bracket (liftIO $ openFile "blah" ReadMode) (liftIO . hClose) > (\fp -> liftIO . mycode $ fp)) > > Another way to use it might be > > runInputT _ (liftIO $ mycode _) `catches` [Handler iohandler, Handler > anotherhandler] > where > iohandler :: IOException -> IO () > iohandler e = putStrLn "got io exception" >> return () > > Exceptions are always a pain, and so are transformers, but you get used to > them. > > On Mon, Aug 1, 2016 at 4:06 AM, Dennis Raddle > wrote: > >> I'm looking over haskeline. It looks like I have to modify some of my >> code that is in the IO monad right now. I use 'evaluate' in several places, >> and also 'evaluate $ force', to make sure that IO exceptions are >> encountered where I can catch them. Can I use 'evaluate' with InputT? I'm >> muddled headed about what to do. I guess I would lift 'evaluate' into the >> inner monad? I am not sure what those words mean. How would I catch IO >> exceptions? >> >> On Thu, Jul 28, 2016 at 5:35 PM, Dennis Raddle >> wrote: >> >>> Thanks. I'll install haskeline >>> >>> On Thu, Jul 28, 2016 at 5:05 PM, David McBride wrote: >>> >>>> You will have to use the haskeline library. FYI that is the library >>>> that makes ghci work. >>>> >>>> On Thu, Jul 28, 2016 at 6:09 PM, Dennis Raddle >>> > wrote: >>>> >>>>> I wrote a program first in Windows, where it works as expected, and >>>>> now I'm using it in OS X and getting undesired behavior. >>>>> >>>>> It reads lines from the terminal using the getLine function. In >>>>> Windows (DOS, actually) the up and down arrows can be used to choose >>>>> previously entered lines. However, this does not work in bash in OS X. >>>>> >>>>> What do I need to get the history available via the arrow keys? >>>>> >>>>> D >>>>> >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at dp.id.au Thu Aug 4 14:26:17 2016 From: dan at dp.id.au (Dan Phillips) Date: Fri, 5 Aug 2016 00:26:17 +1000 Subject: [Haskell-beginners] import Control.Lens.Tutorial Message-ID: Hi all I'm trying to follow this tutorial about lenses: https://hackage.haskell.org/package/lens-tutorial-1.0.1/docs/Control-Lens-Tutorial.html Right at the top of the tutorial,it says do this in ghci: import Control.Lens.Tutorial I tried that, but I got an error: "Could not find module `Control.Lens.Tutorial'" So I tried this: D:\Sync\src\tutorials> stack install lens-tutorial Run from outside a project, using implicit global project config Using resolver: lts-6.9 from implicit global project's config file: C:\Users\dan\AppData\Roaming\stack\global-project\stack.yaml lens-tutorial-1.0.1: download lens-tutorial-1.0.1: configure lens-tutorial-1.0.1: build lens-tutorial-1.0.1: copy/register I'm not exactly sure what that did, but it looked promising. However, I still get the same error in ghci as before when I do the import. My question is, what do I need to do to get the import statement working in ghci so I can follow the tutorial? I would be grateful for any guidance. Thanks. Regards Dan Phillips -------------- next part -------------- An HTML attachment was scrubbed... URL: From frefreak.zxy at gmail.com Thu Aug 4 14:32:59 2016 From: frefreak.zxy at gmail.com (adv_zxy) Date: Thu, 04 Aug 2016 14:32:59 +0000 Subject: [Haskell-beginners] import Control.Lens.Tutorial In-Reply-To: References: Message-ID: Have you tried 'stack exec -- ghci'? This way ghci should be able to find the packages stack installed. On Thu, Aug 4, 2016, 10:27 PM Dan Phillips wrote: > Hi all > > I'm trying to follow this tutorial about lenses: > > > https://hackage.haskell.org/package/lens-tutorial-1.0.1/docs/Control-Lens-Tutorial.html > > > Right at the top of the tutorial,it says do this in ghci: > > import Control.Lens.Tutorial > > > I tried that, but I got an error: "Could not find module > `Control.Lens.Tutorial'" > > So I tried this: > > D:\Sync\src\tutorials> stack install lens-tutorial > Run from outside a project, using implicit global project config > Using resolver: lts-6.9 from implicit global project's config file: > C:\Users\dan\AppData\Roaming\stack\global-project\stack.yaml > lens-tutorial-1.0.1: download > lens-tutorial-1.0.1: configure > lens-tutorial-1.0.1: build > lens-tutorial-1.0.1: copy/register > > I'm not exactly sure what that did, but it looked promising. However, I > still get the same error in ghci as before when I do the import. > > My question is, what do I need to do to get the import statement working > in ghci so I can follow the tutorial? I would be grateful for any guidance. > Thanks. > > Regards > Dan Phillips > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Xiangyu Zhu -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at dp.id.au Thu Aug 4 14:41:35 2016 From: dan at dp.id.au (Dan Phillips) Date: Fri, 5 Aug 2016 00:41:35 +1000 Subject: [Haskell-beginners] import Control.Lens.Tutorial In-Reply-To: References: Message-ID: Awesome. That works. Thanks a lot. 2016-08-05 0:32 GMT+10:00 adv_zxy : > Have you tried 'stack exec -- ghci'? This way ghci should be able to find > the packages stack installed. > > On Thu, Aug 4, 2016, 10:27 PM Dan Phillips wrote: > >> Hi all >> >> I'm trying to follow this tutorial about lenses: >> >> https://hackage.haskell.org/package/lens-tutorial-1.0.1/ >> docs/Control-Lens-Tutorial.html >> >> >> Right at the top of the tutorial,it says do this in ghci: >> >> import Control.Lens.Tutorial >> >> >> I tried that, but I got an error: "Could not find module >> `Control.Lens.Tutorial'" >> >> So I tried this: >> >> D:\Sync\src\tutorials> stack install lens-tutorial >> Run from outside a project, using implicit global project config >> Using resolver: lts-6.9 from implicit global project's config file: >> C:\Users\dan\AppData\Roaming\stack\global-project\stack.yaml >> lens-tutorial-1.0.1: download >> lens-tutorial-1.0.1: configure >> lens-tutorial-1.0.1: build >> lens-tutorial-1.0.1: copy/register >> >> I'm not exactly sure what that did, but it looked promising. However, I >> still get the same error in ghci as before when I do the import. >> >> My question is, what do I need to do to get the import statement working >> in ghci so I can follow the tutorial? I would be grateful for any guidance. >> Thanks. >> >> Regards >> Dan Phillips >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > -- > > Xiangyu Zhu > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.drautzburg at web.de Sat Aug 6 08:03:17 2016 From: martin.drautzburg at web.de (martin) Date: Sat, 6 Aug 2016 10:03:17 +0200 Subject: [Haskell-beginners] My Continuation doesn't typecheck Message-ID: <57A599C5.2030208@web.de> Hello all, in order to gain some intuition about continuations, I tried the following: -- two functions accepting a continuation f1 :: Int -> (Integer->r) -> r f1 a c = c $ fromIntegral (a+1) f2 :: Integer -> (String -> r) -> r f2 b c = c $ show b -- combine the two functions into a single one run1 :: Int -> (String -> r) -> r run1 a = f1 a f2 -- *Main> run1 9 id -- "10" So far so good. Then I tried to write a general combinator, which does not have f1 and f2 hardcoded: combine a f g = f a g -- This also works -- *Main> combine 9 f1 f2 id -- "10" What confuses me is the the type of combine. I thought it should be combine :: Int -> (Int -> (Integer->r) -> r) -> -- f1 (Integer -> (String -> r) -> r) -> -- f2 ((String -> r) -> r) but that doesn't typecheck: Couldn't match expected type ‘(String -> r) -> r’ with actual type ‘r’ Can you tell me where I am making a mistake? From toad3k at gmail.com Sat Aug 6 17:01:00 2016 From: toad3k at gmail.com (David McBride) Date: Sat, 6 Aug 2016 13:01:00 -0400 Subject: [Haskell-beginners] My Continuation doesn't typecheck In-Reply-To: <57A599C5.2030208@web.de> References: <57A599C5.2030208@web.de> Message-ID: The only way to do this is to do it step by step. :t combine combine :: t1 -> (t1 -> t2 -> t) -> t2 -> t >:t combine 9 combine 9 :: Num t1 => (t1 -> t2 -> t) -> t2 -> t >:t f1 f1 :: Int -> (Integer -> r) -> r >:t combine 9 f1 combine 9 f1 :: (Integer -> t) -> t >:t f2 f2 :: Integer -> (String -> r) -> r >:t combine 9 f1 f2 combine 9 f1 f2 :: (String -> r) -> r At some point the t2 in combine becomes a function, which causes the rest of the type to change. I feel like combine was meant to be something else, f (g a) or g (f a) or something else, but I'm not sure what. On Sat, Aug 6, 2016 at 4:03 AM, martin wrote: > Hello all, > > in order to gain some intuition about continuations, I tried the following: > > -- two functions accepting a continuation > > f1 :: Int -> (Integer->r) -> r > f1 a c = c $ fromIntegral (a+1) > > f2 :: Integer -> (String -> r) -> r > f2 b c = c $ show b > > -- combine the two functions into a single one > > run1 :: Int -> (String -> r) -> r > run1 a = f1 a f2 > > > -- *Main> run1 9 id > -- "10" > > So far so good. > > > Then I tried to write a general combinator, which does not have f1 and f2 > hardcoded: > > combine a f g = f a g > > -- This also works > > -- *Main> combine 9 f1 f2 id > -- "10" > > > What confuses me is the the type of combine. I thought it should be > > combine :: Int -> > (Int -> (Integer->r) -> r) -> -- f1 > (Integer -> (String -> r) -> r) -> -- f2 > ((String -> r) -> r) > > > but that doesn't typecheck: > > Couldn't match expected type ‘(String -> r) -> r’ > with actual type ‘r’ > > > Can you tell me where I am making a mistake? > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.drautzburg at web.de Sun Aug 7 11:05:02 2016 From: martin.drautzburg at web.de (martin) Date: Sun, 7 Aug 2016 13:05:02 +0200 Subject: [Haskell-beginners] My Continuation doesn't typecheck In-Reply-To: References: <57A599C5.2030208@web.de> Message-ID: <57A715DE.7060107@web.de> David, I used your method of hardcoding some of the parameters to find the correct type of 'combine'. It is not at all what I expected or wanted, but here it is: combine :: Int -> (Int -> (Integer -> (String -> r) -> r) -> (String -> r) -> r -> String) -> (Integer -> (String -> r) -> r) -> (String -> r) -> r -> String Not sure what this is trying to tell me. Am 08/06/2016 um 07:01 PM schrieb David McBride: > The only way to do this is to do it step by step. > :t combine > combine :: t1 -> (t1 -> t2 -> t) -> t2 -> t > >>:t combine 9 > combine 9 :: Num t1 => (t1 -> t2 -> t) -> t2 -> t > >>:t f1 > f1 :: Int -> (Integer -> r) -> r >>:t combine 9 f1 > combine 9 f1 :: (Integer -> t) -> t > >>:t f2 > f2 :: Integer -> (String -> r) -> r >>:t combine 9 f1 f2 > combine 9 f1 f2 :: (String -> r) -> r > > At some point the t2 in combine becomes a function, which causes the rest of the type to change. I feel like combine > was meant to be something else, f (g a) or g (f a) or something else, but I'm not sure what. > > > On Sat, Aug 6, 2016 at 4:03 AM, martin > wrote: > > Hello all, > > in order to gain some intuition about continuations, I tried the following: > > -- two functions accepting a continuation > > f1 :: Int -> (Integer->r) -> r > f1 a c = c $ fromIntegral (a+1) > > f2 :: Integer -> (String -> r) -> r > f2 b c = c $ show b > > -- combine the two functions into a single one > > run1 :: Int -> (String -> r) -> r > run1 a = f1 a f2 > > > -- *Main> run1 9 id > -- "10" > > So far so good. > > > Then I tried to write a general combinator, which does not have f1 and f2 hardcoded: > > combine a f g = f a g > > -- This also works > > -- *Main> combine 9 f1 f2 id > -- "10" > > > What confuses me is the the type of combine. I thought it should be > > combine :: Int -> > (Int -> (Integer->r) -> r) -> -- f1 > (Integer -> (String -> r) -> r) -> -- f2 > ((String -> r) -> r) > > > but that doesn't typecheck: > > Couldn't match expected type ‘(String -> r) -> r’ > with actual type ‘r’ > > > Can you tell me where I am making a mistake? > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From imantc at gmail.com Sun Aug 7 11:45:54 2016 From: imantc at gmail.com (Imants Cekusins) Date: Sun, 7 Aug 2016 13:45:54 +0200 Subject: [Haskell-beginners] Bool newtype Message-ID: for a Bool-like newtype: newtype B = B Bool , is there an easy way to use this newtype B in place of Bool? e.g. let b1 = B True in if b1 then 1 else 0 ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdorman at jaunder.io Sun Aug 7 12:35:49 2016 From: mdorman at jaunder.io (Michael Alan Dorman) Date: Sun, 07 Aug 2016 08:35:49 -0400 Subject: [Haskell-beginners] Bool newtype In-Reply-To: (Imants Cekusins's message of "Sun, 7 Aug 2016 13:45:54 +0200") References: Message-ID: <87mvkog3iy.fsf@jaunder.io> Imants Cekusins writes: > for a Bool-like newtype: > > newtype B = B Bool > > , is there an easy way to use this newtype B in place of Bool? > > e.g. > > let b1 = B True > in if b1 then 1 else 0 > > ? Imants, You can create a function that converts a B to a Bool: toBool :: B -> Bool toBool B b = b And then use the result of applying that function to your variable: let b1 = B True in if toBool b1 then 1 else 0 To do anything like this automatically would seem to me to defeat the purpose of having distinct types, which is to clearly articulate what values are appropriate in particular contexts. Mike. From dima.samoz at gmail.com Sun Aug 7 12:38:05 2016 From: dima.samoz at gmail.com (Dmitrij Szamozvancev) Date: Sun, 7 Aug 2016 13:38:05 +0100 Subject: [Haskell-beginners] Generalised symbolic expressions Message-ID: Hello all, I'm learning about data types and type classes and tried implementing a simple symbolic expression evaluator, but generalised for non-numeric data types. data GenExpr a = Atom a | Sum (GenExpr a) (GenExpr a) | Prod (GenExpr a) (GenExpr a) | Neg (GenExpr a) What I am hoping to do is write a general evaluation function which can some GenExp expression and evaluate it. For example, giving it a GenExp Integer would evaluate it according to normal arighmetic, GenExp Bool would be evaluated using Boolean algebra etc. I've declared explicit type classes for types that can be summed, multiplied and negated: class HasSum a where (.+.) :: a -> a -> a class HasProd a where (.*.) :: a -> a -> a class HasNeg a where (.-) :: a -> a instance HasSum Integer where (.+.) = (+) instance HasProd Integer where (.*.) = (*) instance HasNeg Integer where (.-) = negate instance HasSum Bool where (.+.) = (||) instance HasProd Bool where (.*.) = (&&) instance HasNeg Bool where (.-) = not -- Evaluate generalised expression genEval :: (HasSum a, HasProd a, HasNeg a) => GenExpr a -> a genEval (Atom a) = a genEval (Sum ge1 ge2) = genEval ge1 .+. genEval ge2 genEval (Prod ge1 ge2) = genEval ge1 .*. genEval ge2 genEval (Neg ge) = (.-) $ genEval ge However, I would like it to work with types that don't support all three operations, e.g. natural numbers which don't have a negation operation or strings that only have concatenation as addition: instance HasSum Nat where (.+.) = (+) instance HasProd Nat where (.*.) = (*) instance HasSum String where (.+.) = (++) But these wouldn't be suitable inputs for genEval because they don't fulfil all three type constraints. The only solution I can think of is writing separate genEvalNat and genEvalString functions, which kind of defeats the purpose of the generalisation. Is there a more elegant way to solve this problem? Thank you in advance! Dima -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdorman at jaunder.io Sun Aug 7 12:49:33 2016 From: mdorman at jaunder.io (Michael Alan Dorman) Date: Sun, 07 Aug 2016 08:49:33 -0400 Subject: [Haskell-beginners] Bool newtype In-Reply-To: (Imants Cekusins's message of "Sun, 7 Aug 2016 13:45:54 +0200") References: Message-ID: <87popku4ki.fsf@aching.i-did-not-set--mail-host-address--so-tickle-me> Imants Cekusins writes: > for a Bool-like newtype: > > newtype B = B Bool > > , is there an easy way to use this newtype B in place of Bool? > > e.g. > > let b1 = B True > in if b1 then 1 else 0 > > ? Imants, You can create a function that converts a B to a Bool: toBool :: B -> Bool toBool B b = b And then use the result of applying that function to your variable: let b1 = B True in if toBool b1 then 1 else 0 To do anything like this automatically would seem to me to defeat the purpose of having distinct types, which is to clearly articulate what values are appropriate in particular contexts. Mike. From imantc at gmail.com Sun Aug 7 13:13:26 2016 From: imantc at gmail.com (Imants Cekusins) Date: Sun, 7 Aug 2016 15:13:26 +0200 Subject: [Haskell-beginners] Bool newtype In-Reply-To: <87mvkog3iy.fsf@jaunder.io> References: <87mvkog3iy.fsf@jaunder.io> Message-ID: True: distinct types help. In this case a function expects a couple bool args so the newtypes help ensure that correct args are passed in correct order. However when working with vals within a function, it may be handy to be able to deduce bool from the newtype, at least to be used with if. This may introduce complexity so not suggesting / requesting anything. Just thought: something might be already available. For example, num-like newtypes can be added, compared as are, without the need to extract the num. Num newtypes conveniently can be derived with "deriving". A function you suggest is good and it works. Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Sun Aug 7 13:41:10 2016 From: imantc at gmail.com (Imants Cekusins) Date: Sun, 7 Aug 2016 15:41:10 +0200 Subject: [Haskell-beginners] Generalised symbolic expressions In-Reply-To: References: Message-ID: Dima, is data GenExpr necessary? ​ would HasSum, HasProd, HasNeg classes & instances not be enough? -------------- next part -------------- An HTML attachment was scrubbed... URL: From marcin.jan.mrotek at gmail.com Sun Aug 7 14:49:39 2016 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Sun, 7 Aug 2016 16:49:39 +0200 Subject: [Haskell-beginners] Bool newtype In-Reply-To: References: <87mvkog3iy.fsf@jaunder.io> Message-ID: Hello, That kind of a function can be also declared automatically, as in: newtype B = B { toBool :: Bool } Best regards, Marcin Mrotek From imantc at gmail.com Sun Aug 7 14:59:38 2016 From: imantc at gmail.com (Imants Cekusins) Date: Sun, 7 Aug 2016 16:59:38 +0200 Subject: [Haskell-beginners] Bool newtype In-Reply-To: References: <87mvkog3iy.fsf@jaunder.io> Message-ID: > newtype B = B { toBool :: Bool } yep, this works well. toBool b1 is easy enough ;) I wondered if there was an easy (with deriving etc) way to test B as it is. If there isn't - no biggie. ​ -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Sun Aug 7 15:13:18 2016 From: imantc at gmail.com (Imants Cekusins) Date: Sun, 7 Aug 2016 17:13:18 +0200 Subject: [Haskell-beginners] Generalised symbolic expressions In-Reply-To: References: Message-ID: > writing separate genEvalNat and genEvalString functions .. here is another possibility: data GenExpr_nat a = ... data GenExpr_string a = ... class GenEval exp a where genEval ::exp a -> a instance GenEval GenExpr_nat a where ... instance GenEval GenExpr_string a where ... ​ -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Sun Aug 7 15:18:05 2016 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Sun, 7 Aug 2016 22:18:05 +0700 Subject: [Haskell-beginners] My Continuation doesn't typecheck In-Reply-To: <57A599C5.2030208@web.de> References: <57A599C5.2030208@web.de> Message-ID: Have you heard of Djinn? https://hackage.haskell.org/package/djinn If you punch in the signature of the combine function you're looking for (rewritten more usefully in Kleisli composition form): (Int -> (Integer->r) -> r) -> (Integer -> (String -> r) -> r) -> (Int -> (String -> r) -> r) you'll get your wish granted. Djinn will magically write combine for you. It'll work even if you abstract over the concrete types of Int, Integer, String. You can popover to the haskell IRC to try it out on the djinn bot there if installation is too much of a bother. Best, Kim-Ee On Saturday, August 6, 2016, martin wrote: > Hello all, > > in order to gain some intuition about continuations, I tried the following: > > -- two functions accepting a continuation > > f1 :: Int -> (Integer->r) -> r > f1 a c = c $ fromIntegral (a+1) > > f2 :: Integer -> (String -> r) -> r > f2 b c = c $ show b > > -- combine the two functions into a single one > > run1 :: Int -> (String -> r) -> r > run1 a = f1 a f2 > > > -- *Main> run1 9 id > -- "10" > > So far so good. > > > Then I tried to write a general combinator, which does not have f1 and f2 > hardcoded: > > combine a f g = f a g > > -- This also works > > -- *Main> combine 9 f1 f2 id > -- "10" > > > What confuses me is the the type of combine. I thought it should be > > combine :: Int -> > (Int -> (Integer->r) -> r) -> -- f1 > (Integer -> (String -> r) -> r) -> -- f2 > ((String -> r) -> r) > > > but that doesn't typecheck: > > Couldn't match expected type ‘(String -> r) -> r’ > with actual type ‘r’ > > > Can you tell me where I am making a mistake? > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From tanuki at gmail.com Sun Aug 7 20:48:24 2016 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Sun, 7 Aug 2016 13:48:24 -0700 Subject: [Haskell-beginners] Bool newtype In-Reply-To: References: <87mvkog3iy.fsf@jaunder.io> Message-ID: As-is, no. As Michael said, that would defeat the purpose of a newtype. However, there is a generic way: all newtypes are given instances of Coercible, so instead of individual unwrap functions you can use coerce from Data.Coerce. On Aug 7, 2016 7:59 AM, "Imants Cekusins" wrote: > > newtype B = B { toBool :: Bool } > > yep, this works well. toBool b1 is easy enough ;) > > I wondered if there was an easy (with deriving etc) way to test B as it > is. If there isn't - no biggie. > > > ​ > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Sun Aug 7 21:12:26 2016 From: imantc at gmail.com (Imants Cekusins) Date: Sun, 7 Aug 2016 23:12:26 +0200 Subject: [Haskell-beginners] Bool newtype In-Reply-To: References: <87mvkog3iy.fsf@jaunder.io> Message-ID: Thank you Theodore. > Data.Coerce Could you hint the name of the package, please? Does it coerce safely? If Coercible does not type check, another option could be to define a class and a function that works similar to if statement, constrained to instances of this class. class Newtype_base nt base where base_t::nt -> base if_::Newtype_base nt Bool => nt -> then -> else Standard if is clearer of course but with a few newtypes being passed around, this may save some key strokes. -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Sun Aug 7 21:15:43 2016 From: imantc at gmail.com (Imants Cekusins) Date: Sun, 7 Aug 2016 23:15:43 +0200 Subject: [Haskell-beginners] Bool newtype In-Reply-To: References: <87mvkog3iy.fsf@jaunder.io> Message-ID: ... this may be correct: if_::Newtype_base nt Bool => nt -> result -> result -> result if_ if0 then0 else0 = ... -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Sun Aug 7 21:47:15 2016 From: imantc at gmail.com (Imants Cekusins) Date: Sun, 7 Aug 2016 23:47:15 +0200 Subject: [Haskell-beginners] Bool newtype In-Reply-To: References: <87mvkog3iy.fsf@jaunder.io> Message-ID: found it: https://wiki.haskell.org/GHC/Coercible yep, it type checks. Ta -------------- next part -------------- An HTML attachment was scrubbed... URL: From chak at justtesting.org Mon Aug 8 04:11:09 2016 From: chak at justtesting.org (Manuel M T Chakravarty) Date: Mon, 8 Aug 2016 14:11:09 +1000 Subject: [Haskell-beginners] Learning Haskell: More About Algebraic Data Types Message-ID: <94290869-E4BB-4C82-A511-3C718A0ACBC6@justtesting.org> We just published a new chapter in our online Haskell tutorial ”Learning Haskell”: http://learn.hfm.io This seventh chapter expands on algebraic data types by discussing parametric & recursive data types. It also includes a small graphics library to graphically render binary tries as you construct and manipulate them. Happy Learning! Manuel From alexander at plaimi.net Mon Aug 8 09:36:19 2016 From: alexander at plaimi.net (Alexander Berntsen) Date: Mon, 8 Aug 2016 11:36:19 +0200 Subject: [Haskell-beginners] reading lines with history from bash terminal in OS X In-Reply-To: References: Message-ID: <57A85293.5000806@plaimi.net> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 You can just run your program via the GNU readline wrapper. - -- Alexander alexander at plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCgAGBQJXqFKTAAoJENQqWdRUGk8Bw9kQAJt69W6tx5nAuBLEBN3Dxbgn ywd2vnlHxAjM5mwhO5fesjHVQrn7KmMNnKCwAZoheN5CzQ+FTloph5b1N5vz8+PW ScbOXkO0DllsEEGm+xVbizMtNBd/jQcTZCfne88L+pN17iB8Tq38BO/Z0wGdHBa6 9wc5zVA8WYIp3Rz6JenCbMMNdkvlJkGPLtFj4Dc4HpjUUf0shkYBD2FLY/+KdJmy TS8rpa8pmUf7iLJtjx08/aq3mlOnUneV1MLMU48YAHSxIirumiN1FqZob9xsJxGy 13oxevngEBfNCfNNHoHFCWxh7ouxvpLKszmwTb25Ts7aOyqPMXifTTrZhL7ZYTad emy/cmbIZu430JbeNTti0gZiqD6ZxjEDXxlFIrAIr/lqoIUghqabKcu2ddq/8pqD VSwymoxTCvJ0sZgpxnCRFwoilZh47W9wPISrIdAjgJTSpGpInzVteXfJi0t49B/G wKUruCO2uZjeznU5iBTPRKBKUab4WhbvF9bJeSPk+tHlNHlqFd3uEFymyB8lHFAu +d/89LUFz+wZXplHgDX4Qd/4SBhUILOdMUr60tCszWuI/HpxoZrLWVtIbZJ5Exvn k6L803FPU6/M1Z2GgB5lRSNOUDm2zJdNK/hpUxXaBQpFVVc/6hK+1WLMS7jZ/hiH eaVanrvlJ6m/kdRRMF0L =0Z0J -----END PGP SIGNATURE----- From martin.drautzburg at web.de Mon Aug 8 14:40:00 2016 From: martin.drautzburg at web.de (martin) Date: Mon, 8 Aug 2016 16:40:00 +0200 Subject: [Haskell-beginners] My Continuation doesn't typecheck In-Reply-To: References: <57A599C5.2030208@web.de> Message-ID: <57A899C0.104@web.de> Am 08/07/2016 um 05:18 PM schrieb Kim-Ee Yeoh: > Have you heard of Djinn? > > https://hackage.haskell.org/package/djinn > > If you punch in the signature of the combine function you're looking for (rewritten more usefully in Kleisli composition > form): > > (Int -> (Integer->r) -> r) -> > (Integer -> (String -> r) -> r) -> > (Int -> (String -> r) -> r) > Thanks for pointing out Djinn, but I want to understand. And there are a number of things I don't understand. Maybe you can help me out: (1) what is the "more useful Kleisli composition" and what would be "less useful" ? (2) I was hoping my experiments would eventually make the Cont monad appear and I originally even named my combinator 'bind' instead of 'combine'. My hope was fueled by the observation that combine a f g = f a g works with f substitued with f1 :: Int -> (Integer->r) -> r and g substitued with f2 :: Integer -> (String -> r) -> r As a next step I would have wrapped (b->r) -> r in a newtype C r b and my functions f1 and f2 would have had the types f1 :: Int -> C r Integer f2 :: Integer -> C r String Now my 'combine' function seems to be different from 'bind' (>>=). It also just too simple to be true. Somwhere I am making a fundamental mistake, but I cannot quite see it. From ky3 at atamo.com Mon Aug 8 15:32:38 2016 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Mon, 8 Aug 2016 22:32:38 +0700 Subject: [Haskell-beginners] My Continuation doesn't typecheck In-Reply-To: <57A899C0.104@web.de> References: <57A599C5.2030208@web.de> <57A899C0.104@web.de> Message-ID: > > (1) what is the "more useful Kleisli composition" and what would be "less > useful" ? This type signature (Int -> (Integer->r) -> r) -> (Integer -> (String -> r) -> r) -> (Int -> (String -> r) -> r) is the Cont monad instantiation of (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c See http://hackage.haskell.org/package/base-4.9.0.0/docs/ Control-Monad.html#v:-62--61--62- Being more uniform, this signature is more useful than the one you had earlier worked with: combine :: Int -> (Int -> (Integer->r) -> r) -> -- f1 (Integer -> (String -> r) -> r) -> -- f2 ((String -> r) -> r) > Now my 'combine' function seems to be different from 'bind' (>>=). It also just too simple to be true. You got Kleisli composition, although not monadic bind. That's still a win of sorts. Best, Kim-Ee Yeoh On Monday, August 8, 2016, martin > wrote: > Am 08/07/2016 um 05:18 PM schrieb Kim-Ee Yeoh: > > Have you heard of Djinn? > > > > https://hackage.haskell.org/package/djinn > > > > If you punch in the signature of the combine function you're looking for > (rewritten more usefully in Kleisli composition > > form): > > > > (Int -> (Integer->r) -> r) -> > > (Integer -> (String -> r) -> r) -> > > (Int -> (String -> r) -> r) > > > > Thanks for pointing out Djinn, but I want to understand. And there are a > number of things I don't understand. Maybe you > can help me out: > > (1) what is the "more useful Kleisli composition" and what would be "less > useful" ? > (2) I was hoping my experiments would eventually make the Cont monad > appear and I originally even named my combinator > 'bind' instead of 'combine'. My hope was fueled by the observation that > > > combine a f g = f a g > > works with > f substitued with f1 :: Int -> (Integer->r) -> r and > g substitued with f2 :: Integer -> (String -> r) -> r > > As a next step I would have wrapped (b->r) -> r in a newtype C r b and my > functions f1 and f2 would have had the types > > f1 :: Int -> C r Integer > f2 :: Integer -> C r String > > Now my 'combine' function seems to be different from 'bind' (>>=). It also > just too simple to be true. > > Somwhere I am making a fundamental mistake, but I cannot quite see it. > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From menemenetekelupharsin at gmx.com Sat Aug 13 18:37:57 2016 From: menemenetekelupharsin at gmx.com (George Taylor) Date: Sat, 13 Aug 2016 20:37:57 +0200 Subject: [Haskell-beginners] Problem getting haskell-mode working with emacs on windows Message-ID: Hello, Environment: Win7 32bit, Emacs 24.5.1, ghci 7.8.3 I have had Haskell working with Windows 7 and emacs previously, but have had issues, and am attempting to get everything working again. Problems. I searched for "Install Haskell Emacs", and found a link to the page https://wiki.haskell.org/Emacs/Installing_haskell-mode But this page was blanked on 11 April 2016, with no information as to where to go. I looked at the previous version of the page, and it said to "place the basic mode haskell-mode.el and the modules you want to use in [a suitable directory, I used "~/haskell-extensions"], add the following command to your init file (~/.emacs): (load "~/lib/emacs/haskell-site-file")" I did the above (but just with haskell-mode.el) and launched emacs, and got a message: "File error: Cannot open load file, no such file or directory, ~/haskell-extensions/haskell-site-file" in emacs, as an experiment, I did M-x Load file: C:\home/haskell-extensions/haskell-mode.el And got the message "Cannot open load file: no such file or directory, haskell-customize" I downloaded haskell-customize.el and placed it in ~/haskell-extensions, and tried again, but no joy. Questions: 0. Is haskell-mode depracated? It no longer seems to be available at MELPA. 1. Why was the page "https://wiki.haskell.org/Emacs/Installing_haskell-mode" blanked? 2. Is a similar, current set of instructions available? 3. Should I be able to load haskell-mode using M-x load-file? If so, what other .el (or other) files are required, and where should they be placed? 4. Is there a dissimilar set of instructions available? Any help will win thousands in prizes. From rein.henrichs at gmail.com Sat Aug 13 20:27:22 2016 From: rein.henrichs at gmail.com (Rein Henrichs) Date: Sat, 13 Aug 2016 20:27:22 +0000 Subject: [Haskell-beginners] Bool newtype In-Reply-To: References: <87mvkog3iy.fsf@jaunder.io> Message-ID: Consider replacing your bools with meaningful sum types, which avoids this issue, prevents boolean blindness, and makes your code more self-documenting. For example, instead of newtype SwitchsState = SwitchState Bool, data SwitchState = On | Off On Sun, Aug 7, 2016 at 2:47 PM Imants Cekusins wrote: > found it: > > https://wiki.haskell.org/GHC/Coercible > > yep, it type checks. > > Ta > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Sun Aug 14 06:06:26 2016 From: imantc at gmail.com (Imants Cekusins) Date: Sun, 14 Aug 2016 08:06:26 +0200 Subject: [Haskell-beginners] Bool newtype In-Reply-To: References: <87mvkog3iy.fsf@jaunder.io> Message-ID: > data SwitchState = On | Off ​ yep, this is clearer than newtype Bool. "If"s may be replaced with "case", and code becomes shorter. Nice one. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonas.beal at novadiscovery.com Wed Aug 17 08:40:07 2016 From: jonas.beal at novadiscovery.com (=?UTF-8?Q?Jonas_B=C3=A9al?=) Date: Wed, 17 Aug 2016 10:40:07 +0200 Subject: [Haskell-beginners] Automatic Differentiation Message-ID: Hello, I have some questions about the Automatic Differentiation package in Haskell (https://hackage.haskell.org/package/ad-4.3.2.1/docs/Numeric-AD.html ) I need to compute the jacobian with that method and I have a type problem, here a simplified example in order to focus on the error: According to documentation I need to write "*jacobian function values*". So I built the input *function. *Please notice this is important for me that my function may depend on an external parameter (named factor here) testFunctionForJacobian :: Fractional a => a -> [a] -> [a] testFunctionForJacobian factor inputs = [(sum inputs) * factor] Then, using *jacobian* function of Numeric.AD in terminal, as a test, it works perfectly >jacobian (testFunctionForJacobian 2) [1,2] < [[2.0,2.0]] No apparent type problem here > :t (testFunctionForJacobian 2) (testFunctionForJacobian 2) :: Fractional a => [a] -> [a] But, I would like to insert that in a bigger function computing the jacobian testJacobian :: Fractional a => a -> [a] -> [[a]] testJacobian factor inputs = jacobian (testFunctionForJacobian factor) inputs This time it generates an error message about *factor* Couldn't match expected type ‘Numeric.AD.Internal.Reverse.Reverse s a’ with actual type ‘a’ ‘a’ is a rigid type variable bound by the type signature for testJacobian :: Fractional a => a -> [a] -> [[a]] s a’ All in all, my type seems implicitly correct in the terminal example but I did not manage to write it explicitly in my function. Here the *jacobian* function signature to help you answer me: -- Jonas Béal -- *This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice.* -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonas.beal at novadiscovery.com Wed Aug 17 08:41:06 2016 From: jonas.beal at novadiscovery.com (=?UTF-8?Q?Jonas_B=C3=A9al?=) Date: Wed, 17 Aug 2016 10:41:06 +0200 Subject: [Haskell-beginners] Automatic Differentiation In-Reply-To: References: Message-ID: jacobian :: (Traversable f, Functor g, Num a) => (forall s. Reifies s Tape => f (Reverse s a) -> g (Reverse s a)) -> f a -> g (f a) Thanks a lot for your help Jonas BÉAL On 17 August 2016 at 10:40, Jonas Béal wrote: > Hello, > > I have some questions about the Automatic Differentiation package in > Haskell (https://hackage.haskell.org/package/ad-4.3.2.1/docs/Numeric > -AD.html) > I need to compute the jacobian with that method and I have a type problem, > here a simplified example in order to focus on the error: > > According to documentation I need to write "*jacobian function values*". > So I built the input *function. *Please notice this is important for me > that my function may depend on an external parameter (named factor here) > testFunctionForJacobian :: Fractional a => a -> [a] -> [a] > testFunctionForJacobian factor inputs = [(sum inputs) * factor] > > Then, using *jacobian* function of Numeric.AD in terminal, as a test, it > works perfectly > >jacobian (testFunctionForJacobian 2) [1,2] > < [[2.0,2.0]] > > No apparent type problem here > > :t (testFunctionForJacobian 2) > (testFunctionForJacobian 2) :: Fractional a => [a] -> [a] > > But, I would like to insert that in a bigger function computing the > jacobian > testJacobian :: Fractional a => a -> [a] -> [[a]] > testJacobian factor inputs = jacobian (testFunctionForJacobian factor) > inputs > > This time it generates an error message about *factor* > Couldn't match expected type ‘Numeric.AD.Internal.Reverse.Reverse > s a’ with actual type ‘a’ > ‘a’ is a rigid type variable bound by the type signature for > testJacobian :: Fractional a => a -> [a] -> [[a]] s a’ > > All in all, my type seems implicitly correct in the terminal example but I > did not manage to write it explicitly in my function. > > Here the *jacobian* function signature to help you answer me: > > > > > > > -- > Jonas Béal > -- Jonas Béal R&D Scientist Intern jonas.beal at novadiscovery.com Novadiscovery The Effect Model Co. www.novadiscovery.com +33 9 72 53 13 00 Bioparc Laënnec, 60 avenue Rockefeller, 69008 Lyon -- *This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice.* -------------- next part -------------- An HTML attachment was scrubbed... URL: From xiut.xu at gmail.com Sun Aug 21 22:05:52 2016 From: xiut.xu at gmail.com (xu xiut) Date: Sun, 21 Aug 2016 16:05:52 -0600 Subject: [Haskell-beginners] help writing a simple api which queries for a resource and displays this info Message-ID: Hello, I am wanting to store something in a database, then retrieve it. That is my entire ambition for the day. Technologies chosen: spock: https://github.com/agrafix/Spock rethinkdb driver: https://github.com/AtnNn/haskell-rethinkdb I chose to go with Rethinkdb, but i'm open to using Postgresql. If someone requests for /companies, I want to list all the companies in the "companies" table. ``` -- ghci λ> companies <- run h $ table "companies" :: IO [Datum] λ> companies [{"name":"tesla","id":"7781ee7e-1e43-4608-bb96-fe10cac3b53a"}] λ> firstCompany <- run h $ table "companies" ! "name" :: IO [Datum] λ> firstCompany ["tesla"] λ> :info Datum data Datum = Null | Bool Bool | String Text | Number Double | Array Database.RethinkDB.Datum.Array | Object Database.RethinkDB.Datum.Object | Time time-1.5.0.1:Data.Time.LocalTime.LocalTime.ZonedTime | Point LonLat | Line GeoLine | Polygon GeoPolygon | Binary bytestring-0.10.6.0:Data.ByteString.Internal.ByteString -- Defined in ‘Database.RethinkDB.Datum’ instance Eq Datum -- Defined in ‘Database.RethinkDB.Datum’ instance Ord Datum -- Defined in ‘Database.RethinkDB.Datum’ instance Show Datum -- Defined in ‘Database.RethinkDB.Datum’ instance Expr Datum -- Defined in ‘Database.RethinkDB.ReQL’ instance Result Datum -- Defined in ‘Database.RethinkDB.Driver’ instance ToDatum Datum -- Defined in ‘Database.RethinkDB.Datum’ instance FromDatum Datum -- Defined in ‘Database.RethinkDB.Datum’ 15:40 < lpaste> xuxu revised “investigating the Datum data type”: “investigating the Datum data type” at http://lpaste.net/179391 ``` I don't know how to display the result. >From Spock's readme, here's an example where I don't need to query the database: ``` main = runSpock 3000 $ spockT id $ do get "companies" $ text $ T.concat ["tesla", "google"] ``` How to convert that into something a little more practial where I do utilize a db? Here's what I have right now, but I'm sure it doesn't compile ``` {-# LANGUAGE OverloadedStrings #-} import Web.Spock import qualified Data.Text as T import qualified Database.RethinkDB as R import qualified Database.RethinkDB.NoClash default (Datum, ReQL, String, Int, Double) main :: IO () main = -- 1. i don't know if the following line will work let h = connect "localhost" 28015 Nothing in runSpock 3000 $ spockT id $ -- 2. list all companies do get "companies" $ text $ T.concat -- something ``` I don't exactly know how "text" works. If I'm reading https://github.com/agrafix/Spock/blob/1ee54503ad67f62af795a31772040f56f7ae08fd/Spock-core/src/Web/Spock/Core.hs#L55 correctly, spockT is using a reader monad. I don't know how it works with the Text type, but I have a suspicion I need to convert Rethink's Datum type into a Text type. I would be absolutely thrilled if anyone is able to help with this. -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Mon Aug 22 10:01:08 2016 From: imantc at gmail.com (Imants Cekusins) Date: Mon, 22 Aug 2016 12:01:08 +0200 Subject: [Haskell-beginners] type T' = T a b c Message-ID: *problem*: given type T with a few parameters e.g. T a b c some functions where this type is passed to, are agnostic to a, b, c i.e. accept T with any of a, b, c processT::T a b c -> () when either number of these parameters or T change (c is dropped or d is added: T a b c d), signatures of every function where T is passed to, need to be updated. *question*: is this possible to specify type synonym T' so that it may be passed to parameter (a,b,c) - agnostic functions so: processT::T' -> () ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Mon Aug 22 10:29:14 2016 From: imantc at gmail.com (Imants Cekusins) Date: Mon, 22 Aug 2016 12:29:14 +0200 Subject: [Haskell-beginners] type T' = T a b c In-Reply-To: References: Message-ID: just came across this: https://downloads.haskell.org/~ghc/7.0.3/docs/html/users_guide/data-type-extensions.html this seems to work: ExistentialQuantification Rank2Types ​ type T' = forall a b. (T a b) -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Mon Aug 22 11:32:15 2016 From: imantc at gmail.com (Imants Cekusins) Date: Mon, 22 Aug 2016 13:32:15 +0200 Subject: [Haskell-beginners] type T' = T a b c In-Reply-To: References: Message-ID: T' and T a b seem to not mix well. T' can not be passed to a function expecting T a b and vice versa any suggestions? ​ -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Mon Aug 22 12:23:18 2016 From: toad3k at gmail.com (David McBride) Date: Mon, 22 Aug 2016 08:23:18 -0400 Subject: [Haskell-beginners] type T' = T a b c In-Reply-To: References: Message-ID: If you want to have something that can ignore a variable, you can just fill it in with (). T Int Char () (), then have a function :: T a b () () -> IO (). You can clean it up a little by making type aliases. type T2 a b = T a b () (), type T3 a b c = T a b c (). On Mon, Aug 22, 2016 at 7:32 AM, Imants Cekusins wrote: > T' and T a b seem to not mix well. > > T' can not be passed to a function expecting T a b and vice versa > > any suggestions? > ​ > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Mon Aug 22 12:40:52 2016 From: imantc at gmail.com (Imants Cekusins) Date: Mon, 22 Aug 2016 14:40:52 +0200 Subject: [Haskell-beginners] type T' = T a b c In-Reply-To: References: Message-ID: David, this seem to work similar to forall...: synonym is not compatible with T a b. you see, I hope to mix synonym with original T a b in a chain of fun calls. Some of the funs accept args like this: fun1::T a b -> a -> out1 .. and others - like this: fun2::T' -> out2 ​ in both cases a and b are not set. However in fun1 I try to enforce type 'a' in the arg #2. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tanuki at gmail.com Mon Aug 22 12:45:46 2016 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Mon, 22 Aug 2016 05:45:46 -0700 Subject: [Haskell-beginners] type T' = T a b c In-Reply-To: References: Message-ID: Go in the other direction? data T a b = T a b type T2 a b c = T a (b, c) type T3 a b c d = T a (b, c, d) On Aug 22, 2016 5:40 AM, "Imants Cekusins" wrote: > David, this seem to work similar to forall...: > > synonym is not compatible with T a b. > > you see, I hope to mix synonym with original T a b in a chain of fun > calls. > > Some of the funs accept args like this: > fun1::T a b -> a -> out1 > > .. and others - like this: > fun2::T' -> out2 > ​ > in both cases a and b are not set. However in fun1 I try to enforce type > 'a' in the arg #2. > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Mon Aug 22 12:51:13 2016 From: imantc at gmail.com (Imants Cekusins) Date: Mon, 22 Aug 2016 14:51:13 +0200 Subject: [Haskell-beginners] type T' = T a b c In-Reply-To: References: Message-ID: > data T a b = T a b > type T2 a b c = T a (b, c) how would this work if T were a record? say: data T a b = T { a::a, b::b, agnostic::Int } could we make a T' (no param) out of it? ​ -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Mon Aug 22 12:56:39 2016 From: imantc at gmail.com (Imants Cekusins) Date: Mon, 22 Aug 2016 14:56:39 +0200 Subject: [Haskell-beginners] type T' = T a b c In-Reply-To: References: Message-ID: ok this may be it: data T a = T { a::a, common::Int } ​ type T' a b = T (a,b) # of record fields stays the same however we cram more data into the 'a' field. it surely works. Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From 50295 at web.de Mon Aug 22 16:07:30 2016 From: 50295 at web.de (Olumide) Date: Mon, 22 Aug 2016 17:07:30 +0100 Subject: [Haskell-beginners] Functions as Applicatives Message-ID: Hi List, I'm struggling to relate the definition of a function as a function instance Applicative ((->) r) where pure x = (\_ -> x) f <*> g = \x -> f x (g x) with the following expression ghci> :t (+) <$> (+3) <*> (*100) (+) <$> (+3) <*> (*100) :: (Num a) => a -> a ghci> (+) <$> (+3) <*> (*100) $ 5 508 From chapter 11 of LYH http://goo.gl/7kl2TM . I understand the explanation in the book: "we're making a function that will use + on the results of (+3) and (*100) and return that. To demonstrate on a real example, when we did (+) <$> (+3) <*> (*100) $ 5, the 5 first got applied to (+3) and (*100), resulting in 8 and 500. Then, + gets called with 8 and 500, resulting in 508." The problem is that I can't relate that explanation with the definition of a function as an applicative; especially f <*> g = \x -> f x (g x) . Is (g x) the second argument to f? Regards, - Olumide From imantc at gmail.com Mon Aug 22 17:34:11 2016 From: imantc at gmail.com (Imants Cekusins) Date: Mon, 22 Aug 2016 19:34:11 +0200 Subject: [Haskell-beginners] Functions as Applicatives In-Reply-To: References: Message-ID: Hello Ollumide, this may help: it builds and runs anyway. ​{- instance Applicative ((->) r) where pure x = (\_ -> x) f <*> g = \x -> f x (g x) with the following expression ghci> :t (+) <$> (+3) <*> (*100) (+) <$> (+3) <*> (*100) :: (Num a) => a -> a ghci> (+) <$> (+3) <*> (*100) $ 5 508 -} f::Num f => f -> f -> f f = (+) g::Num g => g -> g g = (+ 3) h::Num h => h -> h h = (* 100) fg::Num a => a -> a -> a fg = f <$> g {- fg a b = a + (b + 3) fg a = \b -> a + (b + 3) -} fgh::Num a => a -> a fgh = fg <*> h {- fgh b = fg (b * 100) fgh = \b -> fg (b * 100) -} -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Mon Aug 22 17:42:02 2016 From: imantc at gmail.com (Imants Cekusins) Date: Mon, 22 Aug 2016 19:42:02 +0200 Subject: [Haskell-beginners] Functions as Applicatives In-Reply-To: References: Message-ID: fgh::Num a => a -> a fgh = fg <*> h {- fgh a = fg a (a * 100) fgh = \a -> fg a (a * 100) -} , that is ​ -------------- next part -------------- An HTML attachment was scrubbed... URL: From imantc at gmail.com Mon Aug 22 18:13:30 2016 From: imantc at gmail.com (Imants Cekusins) Date: Mon, 22 Aug 2016 20:13:30 +0200 Subject: [Haskell-beginners] Functions as Applicatives In-Reply-To: References: Message-ID: .. actually, I got fg wrong. Caught it by changing g to (/ ): f::Fractional f => f -> f -> f f = (+) g::Fractional g => g -> g g a = a / 2 h::Fractional h => h -> h h = (* 10) fg::Fractional a => a -> a -> a fg = f <$> g {- fg a b = (a / 2) + b fg a = \b -> (a / 2) + b -} fgh::Fractional a => a -> a fgh = fg <*> h {- fgh a = fg a (a * 10) fgh = \a -> fg a (a * 10) -} ​ -------------- next part -------------- An HTML attachment was scrubbed... URL: From rein.henrichs at gmail.com Mon Aug 22 21:14:19 2016 From: rein.henrichs at gmail.com (Rein Henrichs) Date: Mon, 22 Aug 2016 21:14:19 +0000 Subject: [Haskell-beginners] Functions as Applicatives In-Reply-To: References: Message-ID: In f <*> g = \x -> f x (g x), g is the second argument to <*>. The result of f <*> g is a function that takes an argument (x) and gives f x (g x). So basically <*> combines the functions f and g in a particular way to give a new function. In fact, it is the only way to combine them that type checks (and doesn't use undefined or similar). On Mon, Aug 22, 2016 at 11:13 AM Imants Cekusins wrote: > .. actually, I got fg wrong. Caught it by changing g to (/ ): > > > f::Fractional f => f -> f -> f > f = (+) > > g::Fractional g => g -> g > g a = a / 2 > > h::Fractional h => h -> h > h = (* 10) > > > fg::Fractional a => a -> a -> a > fg = f <$> g > {- fg a b = (a / 2) + b > fg a = \b -> (a / 2) + b > -} > > fgh::Fractional a => a -> a > fgh = fg <*> h > {- fgh a = fg a (a * 10) > fgh = \a -> fg a (a * 10) > -} > > ​ > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From 50295 at web.de Mon Aug 22 23:20:26 2016 From: 50295 at web.de (Olumide) Date: Tue, 23 Aug 2016 00:20:26 +0100 Subject: [Haskell-beginners] Functions as Applicatives In-Reply-To: References: Message-ID: What exactly is f x (g x)? is it (f x)(g x)?? ... Looks like two numbers to me e.g. 42 43 ... This can only make sense if they are arguments to another binary function which I don't see. Or is there something I'm missing? - Olumide On 22/08/16 22:14, Rein Henrichs wrote: > In f <*> g = \x -> f x (g x), g is the second argument to <*>. The > result of f <*> g is a function that takes an argument (x) and gives f x > (g x). So basically <*> combines the functions f and g in a particular > way to give a new function. In fact, it is the only way to combine them > that type checks (and doesn't use undefined or similar). > > On Mon, Aug 22, 2016 at 11:13 AM Imants Cekusins > wrote: > > .. actually, I got fg wrong. Caught it by changing g to (/ ): > > > f::Fractional f => f -> f -> f > f = (+) > > g::Fractional g => g -> g > g a = a / 2 > > h::Fractional h => h -> h > h = (* 10) > > > fg::Fractional a => a -> a -> a > fg = f <$> g > {- fg a b = (a / 2) + b > fg a = \b -> (a / 2) + b > -} > > fgh::Fractional a => a -> a > fgh = fg <*> h > {- fgh a = fg a (a * 10) > fgh = \a -> fg a (a * 10) > -} > > ​ > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From tanuki at gmail.com Mon Aug 22 23:54:21 2016 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Mon, 22 Aug 2016 16:54:21 -0700 Subject: [Haskell-beginners] Functions as Applicatives In-Reply-To: References: Message-ID: Yes, (g x) is the second argument to f. Consider the type signature: (<*>) :: Applicative f => f (a -> b) -> f a -> f b In this case, the type of f is ((->) r). Specialized to that type: (<*>) :: (r -> a -> b) -> (r -> a) -> (r -> b) f <*> g = \x -> f x (g x) Breaking down the pieces... f :: r -> a -> b g :: r -> a x :: r (g x) :: a (f x (g x)) :: b The example is made a bit confusing by tossing in an fmap. As far as the definition above is concerned, 'f' in the example is ((+) <$> (+3)) and that has to be resolved before looking at <*>. On Mon, Aug 22, 2016 at 9:07 AM, Olumide <50295 at web.de> wrote: > Hi List, > > I'm struggling to relate the definition of a function as a function > > instance Applicative ((->) r) where > pure x = (\_ -> x) > f <*> g = \x -> f x (g x) > > with the following expression > > ghci> :t (+) <$> (+3) <*> (*100) > (+) <$> (+3) <*> (*100) :: (Num a) => a -> a > ghci> (+) <$> (+3) <*> (*100) $ 5 > 508 > > From chapter 11 of LYH http://goo.gl/7kl2TM . > > I understand the explanation in the book: "we're making a function that > will use + on the results of (+3) and (*100) and return that. To > demonstrate on a real example, when we did (+) <$> (+3) <*> (*100) $ 5, the > 5 first got applied to (+3) and (*100), resulting in 8 and 500. Then, + > gets called with 8 and 500, resulting in 508." > > The problem is that I can't relate that explanation with the definition of > a function as an applicative; especially f <*> g = \x -> f x (g x) . Is (g > x) the second argument to f? > > Regards, > > - Olumide > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rein.henrichs at gmail.com Tue Aug 23 00:01:47 2016 From: rein.henrichs at gmail.com (Rein Henrichs) Date: Tue, 23 Aug 2016 00:01:47 +0000 Subject: [Haskell-beginners] Functions as Applicatives In-Reply-To: References: Message-ID: Here's an example that may help: > ((==) <*> reverse) "radar" True Using the definition for (<*>), we have f = (==) and g = reverse, and this becomes: (==) "radar" (reverse "radar") Or, once we make (==) infix, "radar" == reverse "radar" So we might say: isPalindome x = ((==) <*> reverse) x And we can *eta reduce* that to get isPalindrome = (==) <*> reverse On Mon, Aug 22, 2016 at 4:54 PM Theodore Lief Gannon wrote: > Yes, (g x) is the second argument to f. Consider the type signature: > > (<*>) :: Applicative f => f (a -> b) -> f a -> f b > > In this case, the type of f is ((->) r). Specialized to that type: > > (<*>) :: (r -> a -> b) -> (r -> a) -> (r -> b) > f <*> g = \x -> f x (g x) > > Breaking down the pieces... > f :: r -> a -> b > g :: r -> a > x :: r > (g x) :: a > (f x (g x)) :: b > > The example is made a bit confusing by tossing in an fmap. As far as the > definition above is concerned, 'f' in the example is ((+) <$> (+3)) and > that has to be resolved before looking at <*>. > > > On Mon, Aug 22, 2016 at 9:07 AM, Olumide <50295 at web.de> wrote: > >> Hi List, >> >> I'm struggling to relate the definition of a function as a function >> >> instance Applicative ((->) r) where >> pure x = (\_ -> x) >> f <*> g = \x -> f x (g x) >> >> with the following expression >> >> ghci> :t (+) <$> (+3) <*> (*100) >> (+) <$> (+3) <*> (*100) :: (Num a) => a -> a >> ghci> (+) <$> (+3) <*> (*100) $ 5 >> 508 >> >> From chapter 11 of LYH http://goo.gl/7kl2TM . >> >> I understand the explanation in the book: "we're making a function that >> will use + on the results of (+3) and (*100) and return that. To >> demonstrate on a real example, when we did (+) <$> (+3) <*> (*100) $ 5, the >> 5 first got applied to (+3) and (*100), resulting in 8 and 500. Then, + >> gets called with 8 and 500, resulting in 508." >> >> The problem is that I can't relate that explanation with the definition >> of a function as an applicative; especially f <*> g = \x -> f x (g x) . Is >> (g x) the second argument to f? >> >> Regards, >> >> - Olumide >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From 50295 at web.de Tue Aug 23 11:28:09 2016 From: 50295 at web.de (Olumide) Date: Tue, 23 Aug 2016 12:28:09 +0100 Subject: [Haskell-beginners] Functions as Applicatives In-Reply-To: References: Message-ID: <4aa266c7-5e26-90a8-9422-21c2dee55dce@web.de> I must be missing something. I thought f accepts just one argument. - Olumide On 23/08/2016 00:54, Theodore Lief Gannon wrote: > Yes, (g x) is the second argument to f. Consider the type signature: > > (<*>) :: Applicative f => f (a -> b) -> f a -> f b > > In this case, the type of f is ((->) r). Specialized to that type: > > (<*>) :: (r -> a -> b) -> (r -> a) -> (r -> b) > f <*> g = \x -> f x (g x) > > Breaking down the pieces... > f :: r -> a -> b > g :: r -> a > x :: r > (g x) :: a > (f x (g x)) :: b > > The example is made a bit confusing by tossing in an fmap. As far as the > definition above is concerned, 'f' in the example is ((+) <$> (+3)) and > that has to be resolved before looking at <*>. > > > On Mon, Aug 22, 2016 at 9:07 AM, Olumide <50295 at web.de > > wrote: > > Hi List, > > I'm struggling to relate the definition of a function as a function > > instance Applicative ((->) r) where > pure x = (\_ -> x) > f <*> g = \x -> f x (g x) > > with the following expression > > ghci> :t (+) <$> (+3) <*> (*100) > (+) <$> (+3) <*> (*100) :: (Num a) => a -> a > ghci> (+) <$> (+3) <*> (*100) $ 5 > 508 > > From chapter 11 of LYH http://goo.gl/7kl2TM . > > I understand the explanation in the book: "we're making a function > that will use + on the results of (+3) and (*100) and return that. > To demonstrate on a real example, when we did (+) <$> (+3) <*> > (*100) $ 5, the 5 first got applied to (+3) and (*100), resulting in > 8 and 500. Then, + gets called with 8 and 500, resulting in 508." > > The problem is that I can't relate that explanation with the > definition of a function as an applicative; especially f <*> g = \x > -> f x (g x) . Is (g x) the second argument to f? > > Regards, > > - Olumide > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From tonymorris at gmail.com Tue Aug 23 11:39:43 2016 From: tonymorris at gmail.com (Tony Morris) Date: Tue, 23 Aug 2016 21:39:43 +1000 Subject: [Haskell-beginners] Functions as Applicatives In-Reply-To: <4aa266c7-5e26-90a8-9422-21c2dee55dce@web.de> References: <4aa266c7-5e26-90a8-9422-21c2dee55dce@web.de> Message-ID: <63fa5813-f5ee-e9d7-f0f6-28899ec19c55@gmail.com> All functions in Haskell always take one argument. On 23/08/16 21:28, Olumide wrote: > I must be missing something. I thought f accepts just one argument. > > - Olumide > > On 23/08/2016 00:54, Theodore Lief Gannon wrote: >> Yes, (g x) is the second argument to f. Consider the type signature: >> >> (<*>) :: Applicative f => f (a -> b) -> f a -> f b >> >> In this case, the type of f is ((->) r). Specialized to that type: >> >> (<*>) :: (r -> a -> b) -> (r -> a) -> (r -> b) >> f <*> g = \x -> f x (g x) >> >> Breaking down the pieces... >> f :: r -> a -> b >> g :: r -> a >> x :: r >> (g x) :: a >> (f x (g x)) :: b >> >> The example is made a bit confusing by tossing in an fmap. As far as the >> definition above is concerned, 'f' in the example is ((+) <$> (+3)) and >> that has to be resolved before looking at <*>. >> >> >> On Mon, Aug 22, 2016 at 9:07 AM, Olumide <50295 at web.de >> > wrote: >> >> Hi List, >> >> I'm struggling to relate the definition of a function as a function >> >> instance Applicative ((->) r) where >> pure x = (\_ -> x) >> f <*> g = \x -> f x (g x) >> >> with the following expression >> >> ghci> :t (+) <$> (+3) <*> (*100) >> (+) <$> (+3) <*> (*100) :: (Num a) => a -> a >> ghci> (+) <$> (+3) <*> (*100) $ 5 >> 508 >> >> From chapter 11 of LYH http://goo.gl/7kl2TM . >> >> I understand the explanation in the book: "we're making a function >> that will use + on the results of (+3) and (*100) and return that. >> To demonstrate on a real example, when we did (+) <$> (+3) <*> >> (*100) $ 5, the 5 first got applied to (+3) and (*100), resulting in >> 8 and 500. Then, + gets called with 8 and 500, resulting in 508." >> >> The problem is that I can't relate that explanation with the >> definition of a function as an applicative; especially f <*> g = \x >> -> f x (g x) . Is (g x) the second argument to f? >> >> Regards, >> >> - Olumide >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 473 bytes Desc: OpenPGP digital signature URL: From imantc at gmail.com Tue Aug 23 12:00:01 2016 From: imantc at gmail.com (Imants Cekusins) Date: Tue, 23 Aug 2016 14:00:01 +0200 Subject: [Haskell-beginners] Functions as Applicatives In-Reply-To: <63fa5813-f5ee-e9d7-f0f6-28899ec19c55@gmail.com> References: <4aa266c7-5e26-90a8-9422-21c2dee55dce@web.de> <63fa5813-f5ee-e9d7-f0f6-28899ec19c55@gmail.com> Message-ID: > I thought f accepts just one argument. if f is (+) then f::a -> a -> a ​ -------------- next part -------------- An HTML attachment was scrubbed... URL: From 50295 at web.de Tue Aug 23 14:30:13 2016 From: 50295 at web.de (Olumide) Date: Tue, 23 Aug 2016 15:30:13 +0100 Subject: [Haskell-beginners] Functions as Applicatives In-Reply-To: <63fa5813-f5ee-e9d7-f0f6-28899ec19c55@gmail.com> References: <4aa266c7-5e26-90a8-9422-21c2dee55dce@web.de> <63fa5813-f5ee-e9d7-f0f6-28899ec19c55@gmail.com> Message-ID: On 23/08/2016 12:39, Tony Morris wrote: > All functions in Haskell always take one argument. I know that. All functions accept one argument and return a value _or_ another function. Is f the latter type? - Olumide > > > On 23/08/16 21:28, Olumide wrote: >> I must be missing something. I thought f accepts just one argument. >> >> - Olumide >> >> On 23/08/2016 00:54, Theodore Lief Gannon wrote: >>> Yes, (g x) is the second argument to f. Consider the type signature: >>> >>> (<*>) :: Applicative f => f (a -> b) -> f a -> f b >>> >>> In this case, the type of f is ((->) r). Specialized to that type: >>> >>> (<*>) :: (r -> a -> b) -> (r -> a) -> (r -> b) >>> f <*> g = \x -> f x (g x) >>> >>> Breaking down the pieces... >>> f :: r -> a -> b >>> g :: r -> a >>> x :: r >>> (g x) :: a >>> (f x (g x)) :: b >>> >>> The example is made a bit confusing by tossing in an fmap. As far as the >>> definition above is concerned, 'f' in the example is ((+) <$> (+3)) and >>> that has to be resolved before looking at <*>. >>> >>> >>> On Mon, Aug 22, 2016 at 9:07 AM, Olumide <50295 at web.de >>> > wrote: >>> >>> Hi List, >>> >>> I'm struggling to relate the definition of a function as a function >>> >>> instance Applicative ((->) r) where >>> pure x = (\_ -> x) >>> f <*> g = \x -> f x (g x) >>> >>> with the following expression >>> >>> ghci> :t (+) <$> (+3) <*> (*100) >>> (+) <$> (+3) <*> (*100) :: (Num a) => a -> a >>> ghci> (+) <$> (+3) <*> (*100) $ 5 >>> 508 >>> >>> From chapter 11 of LYH http://goo.gl/7kl2TM . >>> >>> I understand the explanation in the book: "we're making a function >>> that will use + on the results of (+3) and (*100) and return that. >>> To demonstrate on a real example, when we did (+) <$> (+3) <*> >>> (*100) $ 5, the 5 first got applied to (+3) and (*100), resulting in >>> 8 and 500. Then, + gets called with 8 and 500, resulting in 508." >>> >>> The problem is that I can't relate that explanation with the >>> definition of a function as an applicative; especially f <*> g = \x >>> -> f x (g x) . Is (g x) the second argument to f? >>> >>> Regards, >>> >>> - Olumide >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >>> >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From tatiana.moruno at gmail.com Wed Aug 24 00:10:34 2016 From: tatiana.moruno at gmail.com (T. Andrea Moruno Rodriguez) Date: Tue, 23 Aug 2016 20:10:34 -0400 Subject: [Haskell-beginners] =?utf-8?q?No_instance_for_Show_arising_from_a?= =?utf-8?b?IHVzZSBpbiDigJxtYWlu4oCdIGxldmVs?= Message-ID: I have a code that reads files and parses using UU.Parsing lib that returns an abstract sintax tree and shows on the screen. I received the error message "No instance for Show" in my functions originated intokensParserToByteString and applyParser using parseIO (of UU.Parsing lib) and inherited signatures until main. I fixed the signatures but my problem is in the main function. I added the instance Show in the signature but I have the next compilation error: No instance for (Show (IO J2s)) arising from a use of ‘main’ In the expression: main When checking the type of the IO action ‘main’ Some idea, about the problem? Main module ----------------------------------------------------------------------- {-# LANGUAGE FlexibleContexts #-} module Main where import UU.Parsing ... import Content main :: (Show (IO J2s)) => IO() main = do f <- getLine let command = test f command test :: (Show (IO J2s)) => String -> IO() test "testparser" = testParser Test module ----------------------------------------------------------------------- {-# LANGUAGE FlexibleContexts #-} module J2s.Parser.Test where import Content import J2s.Ast.Sintax import J2s.Parser import UU.Parsing ... testParser :: (Show (IO J2s)) => IO() testParser = (runSafeIO $ runProxy $ runEitherK $ contentsRecursive "path/of/my/tests" />/ handlerParser) :: (Show (IO J2s)) => IO() Content module ----------------------------------------------------------------------- {-# LANGUAGE FlexibleContexts #-} module Content where import Control.Monad(forM, liftM) import System.Directory (doesDirectoryExist, getDirectoryContents) import System.FilePath ((), splitExtension, splitFileName) import J2s.Parser import J2s.Ast.Sintax import UU.Parsing import Control.Monad (when, unless) import Control.Proxy import Control.Proxy.Safe hiding (readFileS) import J2s.Scanner.Token import Text.Show import UU.Parsing contentsRecursive :: (CheckP p) => FilePath -> () -> Producer (ExceptionP p) FilePath SafeIO () contentsRecursive path () = loop path where loop path = do contents path () //> \newPath -> do respond newPath isDir <- tryIO $ doesDirectoryExist newPath let isChild = not $ takeFileName newPath `elem` [".", ".."] when (isDir && isChild) $ loop newPath applyParser :: (Proxy p, Show (IO J2s)) => String -> Consumer p B.ByteString IO () applyParser path = runIdentityP loop where loop = do bs <- request () let sc = classify (initPos path) (B8.unpack bs) lift $ B8.putStrLn (tokensParserToByteString sc) tokensParserToByteString :: (Show (IO J2s)) => [Token] -> B.ByteString tokensParserToByteString tokens = B8.pack(show (parseIO pJ2s tokens)) handlerParser :: (CheckP p, Show (IO J2s)) => FilePath -> Session (ExceptionP p) SafeIO () handlerParser path = do canRead <- tryIO $ fmap readable $ getPermissions path isDir <- tryIO $ doesDirectoryExist path isValidExtension <- tryIO $ evaluate ((snd (splitExtension path) == ".java" || snd (splitExtension path) == ".mora") && (snd (splitFileName path) /= "EncodeTest.java") && (snd (splitFileName path) /= "T6302184.java") && (snd (splitFileName path) /= "Unmappable.java")) when (not isDir && canRead && isValidExtension) $ (readFileSP 10240 path >-> try . applyParser) path readFileSP :: (CheckP p) => Int -> FilePath -> () -> Producer (ExceptionP p) B.ByteString SafeIO () readFileSP chunkSize path () = bracket id (openFile path ReadMode) hClose $ \handle -> do let loop = do eof <- tryIO $ hIsEOF handle unless eof $ do bs <- tryIO $ B.hGetSome handle chunkSize respond bs loop loop -- Tatiana Andrea Moruno Rodriguez -------------- next part -------------- An HTML attachment was scrubbed... URL: From tatiana.moruno at gmail.com Wed Aug 24 00:44:04 2016 From: tatiana.moruno at gmail.com (T. Andrea Moruno Rodriguez) Date: Tue, 23 Aug 2016 20:44:04 -0400 Subject: [Haskell-beginners] =?utf-8?q?No_instance_for_Show_arising_from_a?= =?utf-8?b?IHVzZSBpbiDigJxtYWlu4oCdIGxldmVs?= Message-ID: Hi! Yes. Thanks I resolved my problem. The explanation is here: http://stackoverflow.com/questions/39112380/no-instance-for-show-arising-from-a-use-in-main-level?noredirect=1#comment65572477_39112380 2016-08-23 20:23 GMT-04:00 Imants Cekusins : > Hello Tatiana, > > these signatures do not look good: > > main :: (Show (IO J2s)) => IO() > > test :: (Show (IO J2s)) => String -> IO() > > testParser :: (Show (IO J2s)) => IO() > ​ > > constraints are used to specify type variables. IO J2s looks like * (a > fixed type). > > what errors do you see without these constraints? > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis.raddle at gmail.com Wed Aug 24 01:00:34 2016 From: dennis.raddle at gmail.com (Dennis Raddle) Date: Tue, 23 Aug 2016 18:00:34 -0700 Subject: [Haskell-beginners] putting together monadic actions Message-ID: Is there a function foo that does foo :: a -> [a -> m a] -> a So foo 3 [x,x,x] = return 3 >>= x >>= x >>= x I don't think replicateM and sequence do this. At least I can't figure it out. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sylvain at haskus.fr Wed Aug 24 01:33:01 2016 From: sylvain at haskus.fr (Sylvain Henry) Date: Wed, 24 Aug 2016 03:33:01 +0200 Subject: [Haskell-beginners] putting together monadic actions In-Reply-To: References: Message-ID: Hi, You can easily write your own: > import Control.Monad > import Data.List > let foo = flip (foldl' (>=>) return) > :t foo foo :: (Foldable t, Monad m) => b -> t (b -> m b) -> m b > let g x = return (x*2) > foo 3 [g,g,g] 24 -Sylvain On 24/08/2016 03:00, Dennis Raddle wrote: > Is there a function foo that does > > foo :: a -> [a -> m a] -> a > > So > > foo 3 [x,x,x] = return 3 >>= x >>= x >>= x > > I don't think replicateM and sequence do this. At least I can't figure > it out. > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From lee.duhem at gmail.com Wed Aug 24 02:38:52 2016 From: lee.duhem at gmail.com (Lee Duhem) Date: Wed, 24 Aug 2016 10:38:52 +0800 Subject: [Haskell-beginners] Functions as Applicatives In-Reply-To: References: <4aa266c7-5e26-90a8-9422-21c2dee55dce@web.de> <63fa5813-f5ee-e9d7-f0f6-28899ec19c55@gmail.com> Message-ID: On Tue, Aug 23, 2016 at 10:30 PM, Olumide <50295 at web.de> wrote: > On 23/08/2016 12:39, Tony Morris wrote: >> >> All functions in Haskell always take one argument. > > > I know that. All functions accept one argument and return a value _or_ > another function. Is f the latter type? In the ((->) r) case, yes. lee > > - Olumide > > >> >> >> On 23/08/16 21:28, Olumide wrote: >>> >>> I must be missing something. I thought f accepts just one argument. >>> >>> - Olumide >>> >>> On 23/08/2016 00:54, Theodore Lief Gannon wrote: >>>> >>>> Yes, (g x) is the second argument to f. Consider the type signature: >>>> >>>> (<*>) :: Applicative f => f (a -> b) -> f a -> f b >>>> >>>> In this case, the type of f is ((->) r). Specialized to that type: >>>> >>>> (<*>) :: (r -> a -> b) -> (r -> a) -> (r -> b) >>>> f <*> g = \x -> f x (g x) >>>> >>>> Breaking down the pieces... >>>> f :: r -> a -> b >>>> g :: r -> a >>>> x :: r >>>> (g x) :: a >>>> (f x (g x)) :: b >>>> >>>> The example is made a bit confusing by tossing in an fmap. As far as the >>>> definition above is concerned, 'f' in the example is ((+) <$> (+3)) and >>>> that has to be resolved before looking at <*>. >>>> >>>> >>>> On Mon, Aug 22, 2016 at 9:07 AM, Olumide <50295 at web.de >>>> > wrote: >>>> >>>> Hi List, >>>> >>>> I'm struggling to relate the definition of a function as a function >>>> >>>> instance Applicative ((->) r) where >>>> pure x = (\_ -> x) >>>> f <*> g = \x -> f x (g x) >>>> >>>> with the following expression >>>> >>>> ghci> :t (+) <$> (+3) <*> (*100) >>>> (+) <$> (+3) <*> (*100) :: (Num a) => a -> a >>>> ghci> (+) <$> (+3) <*> (*100) $ 5 >>>> 508 >>>> >>>> From chapter 11 of LYH http://goo.gl/7kl2TM . >>>> >>>> I understand the explanation in the book: "we're making a function >>>> that will use + on the results of (+3) and (*100) and return that. >>>> To demonstrate on a real example, when we did (+) <$> (+3) <*> >>>> (*100) $ 5, the 5 first got applied to (+3) and (*100), resulting in >>>> 8 and 500. Then, + gets called with 8 and 500, resulting in 508." >>>> >>>> The problem is that I can't relate that explanation with the >>>> definition of a function as an applicative; especially f <*> g = \x >>>> -> f x (g x) . Is (g x) the second argument to f? >>>> >>>> Regards, >>>> >>>> - Olumide >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From fixpoint.combinator at gmail.com Thu Aug 25 12:18:02 2016 From: fixpoint.combinator at gmail.com (Stanislaw Findeisen) Date: Thu, 25 Aug 2016 14:18:02 +0200 Subject: [Haskell-beginners] cabal install hakyll: global constraint requires installed instance + other conflicts Message-ID: <75aa4390-ba57-c109-9697-b3b6e9c04234@gmail.com> Hi I am trying to install hakyll in a cabal sandbox, but somehow it doesn't work. Here's what I am doing: > $ cabal sandbox init > $ cabal install hakyll > Resolving dependencies... > cabal: Could not resolve dependencies: > trying: hakyll-4.8.3.2 (user goal) > next goal: base (dependency of hakyll-4.8.3.2) > rejecting: base-4.6.0.1/installed-8aa... (conflict: hakyll => base>=4.8 && <5) > rejecting: base-4.9.0.0, 4.8.2.0, 4.8.1.0, 4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0, > 4.6.0.1, 4.6.0.0, 4.5.1.0, 4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0, 4.3.0.0, > 4.2.0.2, 4.2.0.1, 4.2.0.0, 4.1.0.0, 4.0.0.0, 3.0.3.2, 3.0.3.1 (global > constraint requires installed instance) > Backjump limit reached (change with --max-backjumps). > > Note: when using a sandbox, all packages are required to have consistent > dependencies. Try reinstalling/unregistering the offending packages or > recreating the sandbox. Then I tried (inside the sandbox): > $ cabal install cabal-install which installed cabal 1.24.0.0 into the sandbox. Now, when I am using it, I am getting different errors: > $ .cabal-sandbox/bin/cabal install hakyll > Warning: cannot determine version of /usr/lib/ghc/bin/haddock-ghc-7.6.3 : > "" > Resolving dependencies... > cabal: Could not resolve dependencies: > trying: parsec-3.1.11/installed-4f0... (user goal) > trying: pandoc-1.17.2 (dependency of hakyll-4.7.5.2) > next goal: cmark (dependency of pandoc-1.17.2) > rejecting: cmark-0.5.3.1, cmark-0.5.2.1, cmark-0.5.2, cmark-0.5.1, cmark-0.5.0 > (conflict: parsec => text==0.11.3.1/installed-e38..., cmark => text>=1.0 && > <1.3) > rejecting: cmark-0.4.1, cmark-0.4.0.1, cmark-0.3.4, cmark-0.3.3.1, > cmark-0.3.3, cmark-0.3.2, cmark-0.3.1, cmark-0.3.0.1, cmark-0.3, > cmark-0.2.0.2, cmark-0.2.0.1, cmark-0.2, cmark-0.1.0.1, cmark-0.1.0.0 > (conflict: pandoc => cmark>=0.5 && <0.6) > rejecting: cmark-0.5.3 (conflict: parsec => text==0.11.3.1/installed-e38..., > cmark => text>=1.0 && <1.3) > rejecting: cmark-0.3.5 (conflict: pandoc => cmark>=0.5 && <0.6) > Backjump limit reached (currently 2000, change with --max-backjumps or try to > run with --reorder-goals). > > Note: when using a sandbox, all packages are required to have consistent > dependencies. Try reinstalling/unregistering the offending packages or > recreating the sandbox. What is going on here? Why am I getting different errors with the new cabal version? What is the relationship between system-wide packages and those in the sandbox? I thought sandbox is meant to be an isolated environment?!? How do I get the list of all the packages currently installed in the sandbox? Is this: $ ls ./lib/x86_64-linux-ghc-7.6.3/ async-2.1.0 ed25519-0.0.5.0 parsec-3.1.11 base16-bytestring-0.1.1.6 hackage-security-0.5.2.1 random-1.1 base64-bytestring-1.0.0.1 HTTP-4000.3.3 stm-2.4.4.1 bytestring-builder-0.10.8.1.0 mtl-2.2.1 tar-0.5.0.3 Cabal-1.24.0.0 network-2.6.3.1 transformers-0.5.2.0 cryptohash-sha256-0.11.100.1 network-uri-2.6.1.0 zlib-0.6.1.1 the way? Why is 'base' not on the list, although the new cabal is not complaining about it anymore? This is the latest Debian stable. Thanks! -- http://people.eisenbits.com/~stf/ http://www.eisenbits.com/ OpenPGP: 9EC2 5620 2355 B1DC 4A8F 8C79 0EC7 C214 E5AE 3B4E From daniel.trstenjak at gmail.com Thu Aug 25 12:43:17 2016 From: daniel.trstenjak at gmail.com (Daniel Trstenjak) Date: Thu, 25 Aug 2016 14:43:17 +0200 Subject: [Haskell-beginners] cabal install hakyll: global constraint requires installed instance + other conflicts In-Reply-To: <75aa4390-ba57-c109-9697-b3b6e9c04234@gmail.com> References: <75aa4390-ba57-c109-9697-b3b6e9c04234@gmail.com> Message-ID: <20160825124317.GA17703@octa> Hi Stanislaw, > What is going on here? Why am I getting different errors with the new > cabal version? No idea. Perhaps remove the sandbox for the hakyll build and start a new one. > What is the relationship between system-wide packages and those in the > sandbox? I thought sandbox is meant to be an isolated environment?!? Some packages are fixed with the GHC version, like the base one. > How do I get the list of all the packages currently installed in the > sandbox? Is this: > > $ ls ./lib/x86_64-linux-ghc-7.6.3/ > the way? Yes. > Why is 'base' not on the list, although the new cabal is not > complaining about it anymore? The last hakyll version supporting your ghc compiler 7.6.3 was 4.7.5.2. I don't know why cabal gets stuck here, it should take this hakyll version, but you might help cabal with its dependency resolution by directly installing 4.7.5.2: cabal install hakyll-4.7.5.2 Greetings, Daniel From daniel.trstenjak at gmail.com Thu Aug 25 12:46:41 2016 From: daniel.trstenjak at gmail.com (Daniel Trstenjak) Date: Thu, 25 Aug 2016 14:46:41 +0200 Subject: [Haskell-beginners] cabal install hakyll: global constraint requires installed instance + other conflicts In-Reply-To: <75aa4390-ba57-c109-9697-b3b6e9c04234@gmail.com> References: <75aa4390-ba57-c109-9697-b3b6e9c04234@gmail.com> Message-ID: <20160825124641.GA17948@octa> On Thu, Aug 25, 2016 at 02:18:02PM +0200, Stanislaw Findeisen wrote: > $ .cabal-sandbox/bin/cabal install hakyll Wait, have you installed 'cabal-install' into the same sandbox as hakyll? That might cause the issues. Use a separate sandbox for hakyll. From michael at snoyman.com Thu Aug 25 12:55:11 2016 From: michael at snoyman.com (Michael Snoyman) Date: Thu, 25 Aug 2016 12:55:11 +0000 Subject: [Haskell-beginners] cabal install hakyll: global constraint requires installed instance + other conflicts In-Reply-To: <75aa4390-ba57-c109-9697-b3b6e9c04234@gmail.com> References: <75aa4390-ba57-c109-9697-b3b6e9c04234@gmail.com> Message-ID: I'd recommend trying out an installation using the Stack build tool instead. Instructions on installing are available at: https://haskell-lang.org/get-started Once installed, you should be able to install hakyll with: stack install hakyll --install-ghc You'll get a message about the directory the executable is installed into, which should be ~/.local/bin On Thu, Aug 25, 2016, 3:22 PM Stanislaw Findeisen < fixpoint.combinator at gmail.com> wrote: > Hi > > I am trying to install hakyll in a cabal sandbox, but somehow it doesn't > work. Here's what I am doing: > > > $ cabal sandbox init > > $ cabal install hakyll > > Resolving dependencies... > > cabal: Could not resolve dependencies: > > trying: hakyll-4.8.3.2 (user goal) > > next goal: base (dependency of hakyll-4.8.3.2) > > rejecting: base-4.6.0.1/installed-8aa... (conflict: hakyll => base>=4.8 > && <5) > > rejecting: base-4.9.0.0, 4.8.2.0, 4.8.1.0, 4.8.0.0, 4.7.0.2, 4.7.0.1, > 4.7.0.0, > > 4.6.0.1, 4.6.0.0, 4.5.1.0, 4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0, 4.3.0.0, > > 4.2.0.2, 4.2.0.1, 4.2.0.0, 4.1.0.0, 4.0.0.0, 3.0.3.2, 3.0.3.1 (global > > constraint requires installed instance) > > Backjump limit reached (change with --max-backjumps). > > > > Note: when using a sandbox, all packages are required to have consistent > > dependencies. Try reinstalling/unregistering the offending packages or > > recreating the sandbox. > > Then I tried (inside the sandbox): > > > $ cabal install cabal-install > > which installed cabal 1.24.0.0 into the sandbox. Now, when I am using > it, I am getting different errors: > > > $ .cabal-sandbox/bin/cabal install hakyll > > Warning: cannot determine version of /usr/lib/ghc/bin/haddock-ghc-7.6.3 : > > "" > > Resolving dependencies... > > cabal: Could not resolve dependencies: > > trying: parsec-3.1.11/installed-4f0... (user goal) > > trying: pandoc-1.17.2 (dependency of hakyll-4.7.5.2) > > next goal: cmark (dependency of pandoc-1.17.2) > > rejecting: cmark-0.5.3.1, cmark-0.5.2.1, cmark-0.5.2, cmark-0.5.1, > cmark-0.5.0 > > (conflict: parsec => text==0.11.3.1/installed-e38..., cmark => > text>=1.0 && > > <1.3) > > rejecting: cmark-0.4.1, cmark-0.4.0.1, cmark-0.3.4, cmark-0.3.3.1, > > cmark-0.3.3, cmark-0.3.2, cmark-0.3.1, cmark-0.3.0.1, cmark-0.3, > > cmark-0.2.0.2, cmark-0.2.0.1, cmark-0.2, cmark-0.1.0.1, cmark-0.1.0.0 > > (conflict: pandoc => cmark>=0.5 && <0.6) > > rejecting: cmark-0.5.3 (conflict: parsec => text== > 0.11.3.1/installed-e38..., > > cmark => text>=1.0 && <1.3) > > rejecting: cmark-0.3.5 (conflict: pandoc => cmark>=0.5 && <0.6) > > Backjump limit reached (currently 2000, change with --max-backjumps or > try to > > run with --reorder-goals). > > > > Note: when using a sandbox, all packages are required to have consistent > > dependencies. Try reinstalling/unregistering the offending packages or > > recreating the sandbox. > > What is going on here? Why am I getting different errors with the new > cabal version? > What is the relationship between system-wide packages and those in the > sandbox? I thought sandbox is meant to be an isolated environment?!? > > How do I get the list of all the packages currently installed in the > sandbox? Is this: > > $ ls ./lib/x86_64-linux-ghc-7.6.3/ > async-2.1.0 ed25519-0.0.5.0 parsec-3.1.11 > base16-bytestring-0.1.1.6 hackage-security-0.5.2.1 random-1.1 > base64-bytestring-1.0.0.1 HTTP-4000.3.3 stm-2.4.4.1 > bytestring-builder-0.10.8.1.0 mtl-2.2.1 tar-0.5.0.3 > Cabal-1.24.0.0 network-2.6.3.1 > transformers-0.5.2.0 > cryptohash-sha256-0.11.100.1 network-uri-2.6.1.0 zlib-0.6.1.1 > > the way? Why is 'base' not on the list, although the new cabal is not > complaining about it anymore? > > This is the latest Debian stable. > > Thanks! > > -- > http://people.eisenbits.com/~stf/ > http://www.eisenbits.com/ > > OpenPGP: 9EC2 5620 2355 B1DC 4A8F 8C79 0EC7 C214 E5AE 3B4E > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From frederic-emmanuel.picca at synchrotron-soleil.fr Fri Aug 26 14:31:52 2016 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Fri, 26 Aug 2016 14:31:52 +0000 Subject: [Haskell-beginners] GADTs and method signature Message-ID: Hello I have these types data ImageXY data Image3d' data ScPipeParams a where ScPipeParamsImageXY :: ScBitSize -> Channel -> Modulo -> Sc3du -> Roi -> Accumulation -> ScPipeParams ImageXY ScPipeParamsImage3d' :: ScBitSize -> Channel -> Modulo -> Sc3du -> Roi -> Accumulation -> ScPipeParams Image3d' and now I write a method scPipeOpen2' (ScDevDesc dev) p = alloca $ \params -> do poke params p res <- c_sc_pipe_open2 dev (scPipeType p) params checkError res PipeId scPipeOpen2 :: ScDevDesc -> ScPipeParams a -> IO (PipeId) scPipeOpen2 d p@(ScPipeParamsImageXY _ _ _ _ _ _) = scPipeOpen2' d p scPipeOpen2 d p@(ScPipeParamsImage3d' _ _ _ _ _ _) = scPipeOpen2' d p it works fine In order to avoid these _ _ _ _ _ _, I tryed to removed the @(Constructor ____) since I just pass the p parameter to the ' method. But in that case , I get this error message C:\Users\TEMPO\Downloads\tdc\tdc\srcLib.hsc:247:19: No instance for (Storable (ScPipeParams a)) arising from a use of scPipeOpen2' In the expression: scPipeOpen2' d p In an equation for `scPipeOpen2': scPipeOpen2 d p = scPipeOpen2' d p Indeed I already defined two instance of Storable instance Storable (ScPipeParams ImageXY) where ... and instance Storable (ScPipeParams Image3d') where ... Should I use a special extension in order to be able to write only scPipeOpen2 d p = scPipeOpen2' d p thanks for your help Frederic From toad3k at gmail.com Fri Aug 26 19:22:16 2016 From: toad3k at gmail.com (David McBride) Date: Fri, 26 Aug 2016 15:22:16 -0400 Subject: [Haskell-beginners] GADTs and method signature In-Reply-To: References: Message-ID: Once you remove those constructors, when you are operating on 'p' (with poke, I assume) it doesn't know whether you are operating on a ScPipeParams ImageXY or a ScPipeParams Image3d'. The best solution is probably to make instances for Storable ImageXY, and Storable Image3d' and then Storable a => Storable (ScPipeParams a) which utilizes the the Storable instance of whichever parameter 'a' you've provided. If that is not to your liking. I think you can use RecordWildCards extension or maybe it was RecordPuns to allow you to write it something like one of the following. I'm not quite sure whether these would work or not, but it might be worth a try. scPipeOpen2 d p@(ScPipeParamsImage3d' {}) = scPipeOpen2 d p@(ScPipeParamsImage3d' {...}) = On Fri, Aug 26, 2016 at 10:31 AM, PICCA Frederic-Emmanuel < frederic-emmanuel.picca at synchrotron-soleil.fr> wrote: > Hello > > I have these types > > data ImageXY > data Image3d' > > data ScPipeParams a where > ScPipeParamsImageXY :: ScBitSize -> Channel -> Modulo -> Sc3du -> Roi -> > Accumulation -> ScPipeParams ImageXY > ScPipeParamsImage3d' :: ScBitSize -> Channel -> Modulo -> Sc3du -> Roi > -> Accumulation -> ScPipeParams Image3d' > > > and now I write a method > > > scPipeOpen2' (ScDevDesc dev) p = alloca $ \params -> do > poke params p > res <- c_sc_pipe_open2 dev (scPipeType p) params > checkError res PipeId > > scPipeOpen2 :: ScDevDesc -> ScPipeParams a -> IO (PipeId) > scPipeOpen2 d p@(ScPipeParamsImageXY _ _ _ _ _ _) = scPipeOpen2' d p > scPipeOpen2 d p@(ScPipeParamsImage3d' _ _ _ _ _ _) = scPipeOpen2' d p > > it works fine > > In order to avoid these _ _ _ _ _ _, I tryed to removed the @(Constructor > ____) since I just pass the p parameter to the ' method. > But in that case , I get this error message > > C:\Users\TEMPO\Downloads\tdc\tdc\srcLib.hsc:247:19: > No instance for (Storable (ScPipeParams a)) > arising from a use of scPipeOpen2' > In the expression: scPipeOpen2' d p > In an equation for `scPipeOpen2': > scPipeOpen2 d p = scPipeOpen2' d p > > Indeed I already defined two instance of Storable > > instance Storable (ScPipeParams ImageXY) where > ... > > and > > instance Storable (ScPipeParams Image3d') where > ... > > Should I use a special extension in order to be able to write only > > scPipeOpen2 d p = scPipeOpen2' d p > > > thanks for your help > > Frederic > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dominikbollmann at gmail.com Sat Aug 27 13:00:43 2016 From: dominikbollmann at gmail.com (Dominik Bollmann) Date: Sat, 27 Aug 2016 15:00:43 +0200 Subject: [Haskell-beginners] Basic Trie Implementation: Request for Feedback and QuickCheck Question Message-ID: <87vaymnz7o.fsf@t450s.i-did-not-set--mail-host-address--so-tickle-me> Hello Haskellers, I just finished implementing a very simple Trie module, consisting of a Trie data type as well as operations `insert` and `lookup`. Function `insert` inserts a new element into the Trie; function lookup searches for all words in the Trie that match a specific pattern. Besides regular words, a pattern may consist of a single dot '.', indicating that at this position of the search term any letter may occur. For example a pattern "hello" would just search for the word "hello" in the Trie, while ".ello" would search words starting in *any* letter and followed by the sequence "ello" (i.e., it searches for "hello", "Hello", "Aello", etc.) The code for the Trie module can be found here: http://lpaste.net/180768. Regarding the code I have two questions: (1) Since I'm new to Haskell, I'd very much welcome feedback on the general implementation of the Trie module and its two methods what I could improve. (2) While testing the Trie module with QuickCheck, I wrote the property `prop_insert_then_lookup_succeeds` stating that after inserting a word into a Trie it can always successfully be looked up again. While quickchecking this property seems to succeed, I cannot verbose check it. In particular, when I run `verboseCheck prop_insert_then_lookup_succeeds` this property consumes all my main memory and results in the program hanging. Does anyone know what I messed up in devising the quickcheck property? I guess I left open some memory leak... Maybe it has to to with the Arbitrary instance which I might have defined incorrectly? Responses to any of the two questions above are very welcome :-) Thanks! Dominik. From dominikbollmann at gmail.com Sun Aug 28 12:26:40 2016 From: dominikbollmann at gmail.com (Dominik Bollmann) Date: Sun, 28 Aug 2016 14:26:40 +0200 Subject: [Haskell-beginners] Basic Trie Implementation: Request for Feedback and QuickCheck Question In-Reply-To: <87vaymnz7o.fsf@t450s.i-did-not-set--mail-host-address--so-tickle-me> References: <87vaymnz7o.fsf@t450s.i-did-not-set--mail-host-address--so-tickle-me> Message-ID: <87k2f1w03j.fsf@t450s.i-did-not-set--mail-host-address--so-tickle-me> Just a short update, in case anyone reads along. I found the the problem with question (2) from the previous mail: My Arbitrary instance for TrieS was simply wrong and sometimes looped forever, which caused the program to hang. Besides I found another bug (prefixes of words were always found as well) which I've fixed now. The updated code is here: http://lpaste.net/180994 Anyhow, if anyone has any suggestions on how to improve the code style-wise, etc., I would be very happy to hear them! Cheers, Dominik. Dominik Bollmann writes: > Hello Haskellers, > > I just finished implementing a very simple Trie module, consisting of a > Trie data type as well as operations `insert` and `lookup`. Function > `insert` inserts a new element into the Trie; function lookup searches > for all words in the Trie that match a specific pattern. Besides regular > words, a pattern may consist of a single dot '.', indicating that at > this position of the search term any letter may occur. For example a > pattern "hello" would just search for the word "hello" in the Trie, > while ".ello" would search words starting in *any* letter and followed > by the sequence "ello" (i.e., it searches for "hello", "Hello", "Aello", > etc.) > > The code for the Trie module can be found here: http://lpaste.net/180768. > > Regarding the code I have two questions: > > (1) Since I'm new to Haskell, I'd very much welcome feedback on the > general implementation of the Trie module and its two methods what > I could improve. > > (2) While testing the Trie module with QuickCheck, I wrote the > property `prop_insert_then_lookup_succeeds` stating that after > inserting a word into a Trie it can always successfully be looked > up again. While quickchecking this property seems to succeed, I > cannot verbose check it. In particular, when I run > > `verboseCheck prop_insert_then_lookup_succeeds` > > this property consumes all my main memory and results in the > program hanging. > > Does anyone know what I messed up in devising the quickcheck > property? I guess I left open some memory leak... Maybe it has to > to with the Arbitrary instance which I might have defined > incorrectly? > > Responses to any of the two questions above are very welcome :-) > > Thanks! > > Dominik. From haskell-beginners at brisammon.fastmail.fm Sun Aug 28 19:11:24 2016 From: haskell-beginners at brisammon.fastmail.fm (Brian Sammon) Date: Sun, 28 Aug 2016 15:11:24 -0400 Subject: [Haskell-beginners] regex and Unicode Message-ID: <20160828151124.9b07004e2450bc25ae9669a0@brisammon.fastmail.fm> I tried to write a program using Text.Regex.PCRE to search through a UTF8-encoded document. It appears that the presence of non-breaking-space characters (Charpoint 160) triggers some weird behavior in my program. This is using the Debian stable(Jessie) packages of ghc 7.6.3 and libraries. Now I find myself at a fork in the road, not sure which direction to head in. Do I: 1) Continue looking (or get help with looking) for bugs in my code? (I have this reduced to a pretty small test case) 2) Assemble a bug-report against debian? 3) Assemble a bug-report against Text.Regex.PCRE (or Text.Regex.Base) for "upstream" 4) Uninstall Text.Regex.PCRE (and/or some other packages) and switch to something that works with Unicode/UTF8? Any ideas? From haskell at verge.info.tm Sun Aug 28 22:56:29 2016 From: haskell at verge.info.tm (haskell at verge.info.tm) Date: Sun, 28 Aug 2016 22:56:29 +0000 Subject: [Haskell-beginners] How do you show a Data.ByteArray? Message-ID: <2778780b-5c51-bf1b-f9bb-ee2c5a9799d8@verge.info.tm> Prelude Data.ByteArray> c = Data.ByteArray.zero 20 Prelude Data.ByteArray> :type c c :: ByteArray ba => ba Prelude Data.ByteArray> c :38:1: error: • Ambiguous type variable ‘a0’ arising from a use of ‘print’ Uhm... Prelude Data.ByteArray> index c 3 :39:1: error: • Ambiguous type variable ‘a0’ arising from a use of ‘index’ I can't print a byte? From toad3k at gmail.com Sun Aug 28 23:08:19 2016 From: toad3k at gmail.com (David McBride) Date: Sun, 28 Aug 2016 19:08:19 -0400 Subject: [Haskell-beginners] How do you show a Data.ByteArray? In-Reply-To: <2778780b-5c51-bf1b-f9bb-ee2c5a9799d8@verge.info.tm> References: <2778780b-5c51-bf1b-f9bb-ee2c5a9799d8@verge.info.tm> Message-ID: You haven't actually decided what c is, just that it is some type that is an instance of the ByteArray class. :i ByteArray should show: instance ByteArray ByteString instance ByteArray Bytes instance ByteArray ScrubbedBytes try print (c :: ByteString) print (c :: ScrubbedBytes) On Sun, Aug 28, 2016 at 6:56 PM, wrote: > Prelude Data.ByteArray> c = Data.ByteArray.zero 20 > Prelude Data.ByteArray> :type c > c :: ByteArray ba => ba > Prelude Data.ByteArray> c > > :38:1: error: > • Ambiguous type variable ‘a0’ arising from a use of ‘print’ > > Uhm... > > Prelude Data.ByteArray> index c 3 > > :39:1: error: > • Ambiguous type variable ‘a0’ arising from a use of ‘index’ > > I can't print a byte? > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From haskell at verge.info.tm Mon Aug 29 02:17:35 2016 From: haskell at verge.info.tm (haskell at verge.info.tm) Date: Mon, 29 Aug 2016 02:17:35 +0000 Subject: [Haskell-beginners] How do you show a Data.ByteArray? In-Reply-To: References: <2778780b-5c51-bf1b-f9bb-ee2c5a9799d8@verge.info.tm> Message-ID: <661d461d-a8ea-6d71-1514-bfc62160aca4@verge.info.tm> On 08/28/2016 11:08 PM, David McBride wrote: > You haven't actually decided what c is, just that it is some type that is an > instance of the ByteArray class. Thank you! I had thought there was a default instance, like it would by default be Bytes, but could also optionally be wrapped around a ByteString or ScrubbedBytes. But you're right, you can create "20 zeroes" of any of those underlying things. Makes a lot more sense now. From laiboonh at gmail.com Mon Aug 29 14:56:46 2016 From: laiboonh at gmail.com (Lai Boon Hui) Date: Mon, 29 Aug 2016 22:56:46 +0800 Subject: [Haskell-beginners] Why is the type constraint different from signature? Message-ID: Hi All, can some one explain to me why ghci> let f:: (Ord a, Num b) => a -> b -> a ; f=undefined ghci> :t f 1 2 ghci> f 1 2 :: (Num a, Ord a) => a The initial type signature just required *a* to be a type that is an instance of Ord but after it had the additional constraint of Ord as well??? -- Best Regards, Boon Hui -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Mon Aug 29 15:08:23 2016 From: toad3k at gmail.com (David McBride) Date: Mon, 29 Aug 2016 11:08:23 -0400 Subject: [Haskell-beginners] Why is the type constraint different from signature? In-Reply-To: References: Message-ID: >:t f f :: (Num b, Ord a) => a -> b -> a a is an instance of Ord b is an instance of Num >:t 1 1 :: Num a => a >:t f 1 f 1 :: (Num a, Num b, Ord a) => b -> a the literal 1 is an instance of Num, therefore a must be an instance of Ord but now also of Num What we know about a is that it must be a Num (because we assigned it the literal 1 which is a Num) and that it must also be an Ord (because your original type signature specified that it must also be an Ord). On Mon, Aug 29, 2016 at 10:56 AM, Lai Boon Hui wrote: > Hi All, > > can some one explain to me why > > ghci> let f:: (Ord a, Num b) => a -> b -> a ; f=undefined > ghci> :t f 1 2 > ghci> f 1 2 :: (Num a, Ord a) => a > > The initial type signature just required *a* to be a type that is an > instance of Ord but after it had the additional constraint of Ord as well??? > > > -- > Best Regards, > Boon Hui > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From umptious at gmail.com Tue Aug 30 19:47:43 2016 From: umptious at gmail.com (umptious) Date: Tue, 30 Aug 2016 20:47:43 +0100 Subject: [Haskell-beginners] Could anyone explain what this means? (Haskell wiki entry on monads) Message-ID: >>Each monad, or computation type<< That seems to be saying that monad and "computation type" are synonyms. But surely this is just bad writing? A monad is a CT, but a CT doesn't have to be a monad? And what is the point of adding the verbiage of "computation type" in what will be a massive sentence anyway? >>provides means, subject to *Monad Laws*,<< I think it's expected that monads will follow monad laws and provide means to do something.. >>> to *(a)* *create* a description of computation action that will produce (a.k.a. "return") a given Haskell value<<< This is just bizarre. The monad can create a description of a computation action? What does that mean - a comment is a description - does it mean that? And does it mean the description will do the returning or that the computation action will? And why say "means" instead of something more specific and meaningful (for example, I'm guessing the means might be a function..) -------------- next part -------------- An HTML attachment was scrubbed... URL: From gesh at gesh.uni.cx Tue Aug 30 22:56:08 2016 From: gesh at gesh.uni.cx (Gesh) Date: Wed, 31 Aug 2016 01:56:08 +0300 Subject: [Haskell-beginners] Could anyone explain what this means? (Haskell wiki entry on monads) In-Reply-To: References: Message-ID: <17cbf2f9-fe40-747a-9251-cfd5e7101abe@gesh.uni.cx> I agree with you that the phrasing could be better. On 2016-08-30 22:47, umptious wrote: > > >>Each monad, or computation type<< > > That seems to be saying that monad and "computation type" are > synonyms. But surely this is just bad writing? A monad is a CT, but a > CT doesn't have to be a monad? And what is the point of adding the > verbiage of "computation type" in what will be a massive sentence anyway? What they seem to be trying to convey here is that each monad represents a type of computation. E.g. the list monad represents nondeterministic computation, the Maybe monad represents failable computation, the Either monad represents computations that may throw exceptions, etc. Basically, the point here is to present the weird and abstract "monad" in terms of the more familiar and intuitive notion of "computation". The word "type" here refers to the intuitive sense, and not the type-theoretic/programmer's sense IIUC. > >>provides means, subject to /*Monad Laws*/,<< > > I think it's expected that monads will follow monad laws and provide > means to do something.. That's clear post priori. That is, obviously, if there are "Foo Laws", then we'd expect Foos to satisfy them. If it was clear to you at the onset, good for you! You're well on your way to developing the mindset used in many libraries (e.g. pipes/conduit, lens, etc.) which is to approach any new concept with the question "What laws must it satisfy?" I assume the second half of your remark is pure snark. (Statement necessary due to difficulty distinguishing snark from questions) > >>> to /*(a)*/ /create/ a description of computation action that will > produce (a.k.a. "return") a given Haskell value<<< > > This is just bizarre. The monad can create a description of a > computation action? What does that mean - a comment is a description - > does it mean that? And does it mean the description will do the > returning or that the computation action will? And why say "means" > instead of something more specific and meaningful (for example, I'm > guessing the means might be a function..) An example would make it easier to see what is meant, in my opinion. Consider the definitions > data State s a = Return a | Get (s -> State s a) | Set s (State s a) > instance Functor (State s) where > fmap f (Return a) = Return a > fmap f (Get t) = Get (\s -> fmap f (t s)) > fmap f (Set s n) = Set s (fmap f n) > instance Monad (State s) where > return = Return > Return a >>= f = f a > m >>= f = fmap (>>= f) m > get = Get Return > set s = Set s (Return ()) > modify f = get >>= \s -> set (f s) > runState (Return a) _ = a > runState (Get t) s = runState (t s) > runState (Set s n) _ = runState n s With these definitions in hand, we can write programs such as: > sum = runState go 0 > where go [] = get > go (x:xs) = modify (+x) >> go xs Note, however, that `State` only *describes* a stateful computation. We could do other things with the value returned by `go` (e.g., count the amount of modifications to the global state). In other words, the point is that monads can be seen as describing a program in a language with semantics wildly different from Haskell's, where at the end of the day we interpret the program using whichever interpreter is most useful to us. Hence, despite Haskell being pure and functional, we can write code that makes use of e.g. pointer manipulation, randomness, nondeterminism, etc. In fact, the fact that in Haskell we have `main :: IO a` means that the value of `main` is the "program text" of some imperative program that gets passed to GHC's runtime system, which is capable of interpreting this imperative program. It is in this sense, if I'm not mistaken, that Simon Peyton-Jones refers to Haskell as the "world's finest imperative programming language"[0]. I hope this will reduce confusion, rather than create it. Gesh [0] - https://www.microsoft.com/en-us/research/wp-content/uploads/2016/07/mark.pdf From gesh at gesh.uni.cx Wed Aug 31 03:03:46 2016 From: gesh at gesh.uni.cx (Gesh) Date: Wed, 31 Aug 2016 06:03:46 +0300 Subject: [Haskell-beginners] Learning Monads with 'setjmp' and 'longjmp' like actions In-Reply-To: <5794F814.5010904@mroth.net> References: <5794F814.5010904@mroth.net> Message-ID: <5a15efaa-2acd-432c-f344-78fb8ebb9f4c@gesh.uni.cx> On 2016-07-24 20:17, Michael Roth wrote: > Hi, > > I'm really trying hard to understand monads but I guess my brain is > trapped in the imperative world. > > Below what I have done so far. But now I would like to implement > something like this: > > do > foo > (label, jumped) <- setjmp > bar > longjmp label > > But I'm stuck. How can I implement 'setjmp' and 'longjmp' with my monad? > I'm not able to grasp how can I design 'setjmp' and somehow create a > label to use in 'longjmp'. > Maybe my monad structure is not appropriate? > > > Code follows: > --------------------------------------------------------------- > > data World = SomeWorld > deriving (Eq, Show) > > data ProgramResult a = > Result { world :: World, result :: a } > | Continue { world :: World, continue :: Program a } > | Stopped { world :: World } Firstly, you are correct in noting that `setjmp`/`longjmp` aren't implementable in your monad. Your monad is a variation on the following one: > data Lazy a = Value a | Thunk (() -> Lazy a) with the obvious instances. In essence, given that your `World` type is opaque, I'm treating it as isomorphic to (). Given that, we have `ProgramResult a ~ Lazy (Maybe a)`. In contrast, `setjmp`/`longjmp` are *much* more powerful than that. Any monad in which one can implement them can be used to implement `callCC`. One can embed the `Cont` monad into such monads (writing the code to do this is left as an exercise). However, one can embed any monad into `Cont`[0], from which it should be intuitively obvious that your monad is not up to the task. Moreover, usually `setjmp`/`longjmp` is not what you want. Derek Elkins explains this much better than I can[1], but in brief the problem with `setjmp` is that the continuation that it corresponds to contains its own use, which means you need to test whether the current execution of the code occurs before the first call to `longjmp`. The alternative he recommends is `callCC`, which is equivalent in power to `setjmp`/`longjmp` but whose usage is simpler. Hope this helps, despite the original question being over a month old. Gesh [0] - https://www.schoolofhaskell.com/school/advanced-haskell/the-mother-of-all-monads [1] - http://lambda-the-ultimate.org/node/3611#comment-51086 P.S. An untested implementation of `setjmp`/`longjmp` in `Cont`: > throw :: r -> Cont r b > throw e = Cont $ \_ -> e > setjmp :: Cont r (Either (a -> Cont r b) a) > setjmp = Cont $ \c-> c (Left (throw . c . Right)) > longjmp :: (a -> Cont r b) -> a -> Cont r b > longjmp c v = c v From haskell-beginners at brisammon.fastmail.fm Wed Aug 31 03:16:57 2016 From: haskell-beginners at brisammon.fastmail.fm (Brian Sammon) Date: Tue, 30 Aug 2016 23:16:57 -0400 Subject: [Haskell-beginners] regex and Unicode In-Reply-To: <20160828151124.9b07004e2450bc25ae9669a0@brisammon.fastmail.fm> References: <20160828151124.9b07004e2450bc25ae9669a0@brisammon.fastmail.fm> Message-ID: <20160830231657.c9d628dfa538d8e795ab59ba@brisammon.fastmail.fm> On Sun, 28 Aug 2016 15:11:24 -0400 Brian Sammon wrote: > I tried to write a program using Text.Regex.PCRE to search through a UTF8- > encoded document. It appears that the presence of non-breaking-space > characters (Charpoint 160) triggers some weird behavior in my program. Well switching my code to use Text.RegexPR-based searches rather than Text.Regex.PCRE made the problem go away. Text.Regex.PCRE seems to be unmaintained, so I guess I shouldn't be surprised that I had problems with it.