From amy at nualeargais.ie Sun Dec 2 19:20:33 2018 From: amy at nualeargais.ie (=?UTF-8?Q?Amy_de_Buitl=C3=A9ir?=) Date: Sun, 02 Dec 2018 19:20:33 +0000 Subject: [Haskell-cafe] Can't get Type 3" to work Message-ID: <0043b9b3755675074cdcd71299eee0e8@nualeargais.ie> I'm reading "Thinking with Types" by Sandy Maguire, and there's a bit of code on p. 27 that I don't understand and can't get to work. The "Type 3" seems to have the effect of multiplying by 3. > :set -XDataKinds > :set -XTypeOperators > :kind! (1 + 17) Type 3 (1 + 17) Type 3 :: Nat = 54 But it doesn't work for me. When I try this, I get... $ ghci --version The Glorious Glasgow Haskell Compilation System, version 8.2.2 $ ghci λ> :set -XDataKinds λ> :set -XTypeOperators λ> :kind! (1 + 17) Type 3 :1:2: error: Not in scope: type constructor or class '+' :1:10: error: Not in scope: type constructor or class 'Type' -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Mon Dec 3 00:12:22 2018 From: allbery.b at gmail.com (Brandon Allbery) Date: Sun, 2 Dec 2018 19:12:22 -0500 Subject: [Haskell-cafe] Can't get Type 3" to work In-Reply-To: <0043b9b3755675074cdcd71299eee0e8@nualeargais.ie> References: <0043b9b3755675074cdcd71299eee0e8@nualeargais.ie> Message-ID: That looks like someone had a search-and-replace error. It used to be that the kind of normal values was *. Type level math made this problematic; by default, in recent ghc that kind is called Type instead. (See the StarIsType LANGUAGE pragma.) So someone did a search and replace to fix the kinds, and changed what should have been a type level multiplication by accident. Change it to a*. On Sun, Dec 2, 2018 at 7:09 PM Amy de Buitléir wrote: > I'm reading "Thinking with Types" by Sandy Maguire, and there's a bit of > code on p. 27 that I don't understand and can't get to work. The "Type 3" > seems to have the effect of multiplying by 3. > > > :set -XDataKinds > > :set -XTypeOperators > > :kind! (1 + 17) Type 3 > > (1 + 17) Type 3 :: Nat > = 54 > > But it doesn't work for me. When I try this, I get... > > $ ghci --version > The Glorious Glasgow Haskell Compilation System, version 8.2.2 > > $ ghci > > λ> :set -XDataKinds > λ> :set -XTypeOperators > λ> :kind! (1 + 17) Type 3 > > :1:2: error: > Not in scope: type constructor or class ‘+’ > > :1:10: error: > Not in scope: type constructor or class ‘Type’ > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -- brandon s allbery kf8nh allbery.b at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From amy at nualeargais.ie Mon Dec 3 00:49:19 2018 From: amy at nualeargais.ie (=?UTF-8?Q?Amy_de_Buitl=C3=A9ir?=) Date: Mon, 03 Dec 2018 00:49:19 +0000 Subject: [Haskell-cafe] Can't get Type 3" to work In-Reply-To: References: <0043b9b3755675074cdcd71299eee0e8@nualeargais.ie> Message-ID: Ah, thank you, that makes perfect sense. For anyone else who struggles with that example, you also need :set -XTypeOperators and import GHC.TypeLits. λ> :set -XDataKinds λ> :set -XTypeOperators λ> import GHC.TypeLits λ> :kind! (1 + 17) * 3 (1 + 17) * 3 :: Nat = 54 Unfortunately, I also get an error on the next line: λ> :kind! (Div 128 8) ^ 2 :1:2: error: Not in scope: type constructor or class 'Div' Div is defined in GHC.TypeLits, so I don't understand why that didn't work. On 2018-12-03 00:12, Brandon Allbery wrote: > That looks like someone had a search-and-replace error. > > It used to be that the kind of normal values was *. Type level math made this problematic; by default, in recent ghc that kind is called Type instead. (See the StarIsType LANGUAGE pragma.) > > So someone did a search and replace to fix the kinds, and changed what should have been a type level multiplication by accident. Change it to a*. > > On Sun, Dec 2, 2018 at 7:09 PM Amy de Buitléir wrote: > >> I'm reading "Thinking with Types" by Sandy Maguire, and there's a bit of code on p. 27 that I don't understand and can't get to work. The "Type 3" seems to have the effect of multiplying by 3. >> >>> :set -XDataKinds >>> :set -XTypeOperators >>> :kind! (1 + 17) Type 3 >> >> (1 + 17) Type 3 :: Nat >> = 54 >> >> But it doesn't work for me. When I try this, I get... >> >> $ ghci --version >> The Glorious Glasgow Haskell Compilation System, version 8.2.2 >> >> $ ghci >> >> λ> :set -XDataKinds >> λ> :set -XTypeOperators >> λ> :kind! (1 + 17) Type 3 >> >> :1:2: error: >> Not in scope: type constructor or class '+' >> >> :1:10: error: >> Not in scope: type constructor or class 'Type' _______________________________________________ >> Haskell-Cafe mailing list >> To (un)subscribe, modify options or view archives go to: >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> Only members subscribed via the mailman list are allowed to post. > > -- > > brandon s allbery kf8nh > allbery.b at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From vagarenko at gmail.com Mon Dec 3 01:06:14 2018 From: vagarenko at gmail.com (Alexey Vagarenko) Date: Mon, 3 Dec 2018 06:06:14 +0500 Subject: [Haskell-cafe] Can't get Type 3" to work In-Reply-To: References: <0043b9b3755675074cdcd71299eee0e8@nualeargais.ie> Message-ID: Div was introduced in GHC 8.4, I believe. пн, 3 дек. 2018 г. в 05:49, Amy de Buitléir : > Ah, thank you, that makes perfect sense. For anyone else who struggles > with that example, you also need :set -XTypeOperators and import > GHC.TypeLits. > > λ> :set -XDataKinds > λ> :set -XTypeOperators > λ> import GHC.TypeLits > λ> :kind! (1 + 17) * 3 > (1 + 17) * 3 :: Nat > = 54 > > Unfortunately, I also get an error on the next line: > > λ> :kind! (Div 128 8) ^ 2 > > :1:2: error: > Not in scope: type constructor or class ‘Div’ > > Div is defined in GHC.TypeLits, so I don't understand why that didn't work. > > > On 2018-12-03 00:12, Brandon Allbery wrote: > > That looks like someone had a search-and-replace error. > > It used to be that the kind of normal values was *. Type level math made > this problematic; by default, in recent ghc that kind is called Type > instead. (See the StarIsType LANGUAGE pragma.) > > So someone did a search and replace to fix the kinds, and changed what > should have been a type level multiplication by accident. Change it to a*. > > On Sun, Dec 2, 2018 at 7:09 PM Amy de Buitléir wrote: > >> I'm reading "Thinking with Types" by Sandy Maguire, and there's a bit of >> code on p. 27 that I don't understand and can't get to work. The "Type 3" >> seems to have the effect of multiplying by 3. >> >> > :set -XDataKinds >> > :set -XTypeOperators >> > :kind! (1 + 17) Type 3 >> >> (1 + 17) Type 3 :: Nat >> = 54 >> >> But it doesn't work for me. When I try this, I get... >> >> $ ghci --version >> The Glorious Glasgow Haskell Compilation System, version 8.2.2 >> >> $ ghci >> >> λ> :set -XDataKinds >> λ> :set -XTypeOperators >> λ> :kind! (1 + 17) Type 3 >> >> :1:2: error: >> Not in scope: type constructor or class '+' >> >> :1:10: error: >> Not in scope: type constructor or class 'Type' >> _______________________________________________ >> Haskell-Cafe mailing list >> To (un)subscribe, modify options or view archives go to: >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> Only members subscribed via the mailman list are allowed to post. > > > > -- > brandon s allbery kf8nh > allbery.b at gmail.com > > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From amy at nualeargais.ie Mon Dec 3 01:30:53 2018 From: amy at nualeargais.ie (=?UTF-8?Q?Amy_de_Buitl=C3=A9ir?=) Date: Mon, 03 Dec 2018 01:30:53 +0000 Subject: [Haskell-cafe] Can't get Type 3" to work In-Reply-To: References: <0043b9b3755675074cdcd71299eee0e8@nualeargais.ie> Message-ID: Thank you. I upgraded my GHC and it works now. On 2018-12-03 01:06, Alexey Vagarenko wrote: > Div was introduced in GHC 8.4, I believe. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikivazou at gmail.com Mon Dec 3 18:33:41 2018 From: nikivazou at gmail.com (Niki Vazou) Date: Mon, 3 Dec 2018 19:33:41 +0100 Subject: [Haskell-cafe] Open PhD and intern positions at IMDEA Message-ID: Hi Haskellers, I recently joined IMDEA and looking for talented Ph.D. students and interns to work with. Projects My current open projects focus on how to establish Liquid Haskell as a practical and useful theorem prover. Ideas I would like to explore include: - *Integration with Compiler & Compiler Optimizations:* The major goal of verification is to prove that your code satisfies certain correctness properties. But, once your correctness properties are proved, the compiler could use them to optimize the running times. For example properties like associativity, map fusion, and class laws could, and should, be used for provably correct compiler optimizations. The goal of this project is how the Haskell compiler can automatically take full advantage of Liquid Haskell generated proofs. - *Error Reporting:* Error messages are terrible! This is the case in most systems that include type inference, see ghc, and Liquid Haskell is not an exception. Recently , the idea of using gradual types for error explanation was explored. The goal of this project is to further explore the interaction between gradual types and error reporting, or use further concepts, such as testing to aid error explanation. - *Interactive Proving Environment:* For theorem proving to be usable, proof generation should be interactively directed by the prover. Towards this goal, this project aims to investigate how existing techniques such as tactics and interactive environments from interactive theorem provers like Coq and Isabelle/HOL can be adapted to aid proof generation in Liquid Haskell. At the same time, proof generation can be aided by Haskell’s code generation infrastructures such as the automatic code derivation mechanisms. My passion is functional programing and practical program verification, so I am happy to discuss new research ideas in any of these directions. Requirements If you want to apply for a Ph.D. position you are required to have an undergraduate degree in Computer Science or a closely related area and have strong interest in functional programming. About IMDEA The IMDEA Software Institute is ranked among the best european institutes in the areas of Programming Languages and Computer Security. Located in the Montegancedo Science and Technology Park it perfectly combines the sunny and vibrant city of Madrid with cutting edge research and competitive salaries. How to apply? To apply send me an email at niki.vazou at imdea.org with your CV and submit an online application at IMDEA’s open positions . Best, Niki Vazou -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon at joyful.com Mon Dec 3 23:09:00 2018 From: simon at joyful.com (Simon Michael) Date: Mon, 3 Dec 2018 15:09:00 -0800 Subject: [Haskell-cafe] ANN: hledger-1.12 Message-ID: <8E2E6DD1-A175-413A-985F-0A38BF302C1D@joyful.com> hledger is a robust, cross-platform plain text accounting tool, for tracking money, time, stocks, cryptocurrencies or any other commodity, using double-entry accounting, private or shared plain text files, revision control, and command-line, curses or web UIs. Find out more at http://hledger.org and http://plaintextaccounting.org. I'm pleased to announce the release of hledger 1.12! Thank you release contributors Alex Chen, Jesse Rosenthal, Samuel May, Mykola Orliuk, Peter Simons, Moritz Kiefer, Dmitry Astapov, Felix Yan, Aiken Cairncross, and Nikhil Jha. After two years of regular quarter-end releases, I am speeding up hledger's release cadence: we now aim to release every 1-3 months, as needed or wanted, with our normal release window being the first few days of each month. Release notes (http://hledger.org/release-notes): ------------------------------------------------- hledger 1.12 * install script: ensure a new-enough version of stack; more informative output * build with GHC 8.6/base-4.12 (Peter Simons) * add required upper bound for statistics (Samuel May) * --anon anonymises more thoroughly (including linked original postings) (Moritz Kiefer) * unbalanced transaction errors now include location info (Mykola Orliuk) * accounts command: --drop also affects the default flat output, without needing an explicit --flat flag * accounts command: the --codes flag has been dropped * accounts command: filtering by non-account-name queries now works * add command: fix transaction rendering regression during data entry and in journal file * balance command: fix wrongful eliding of zero-balance parent accounts in tree mode (Dmitry Astapov) * journal format, bs/bse/cf/is commands: account directives can declare account types (#877) Previously you had to use one of the standard english account names (assets, liabilities..) for top-level accounts, if you wanted them to appear in the right place in the balancesheet, balancesheetequity, cashflow or incomestatement reports. Now you can use your preferred account names, and use account directives to declare which accounting class (Asset, Liability, Equity, Revenue or eXpense) an account (and its subaccounts) belongs to, by writing one of the letters A, L, E, R, X after the account name, after two or more spaces. This syntax may change (see issue). Experimental. Currently we allow unlimited account type declarations anywhere in the account tree. So you could declare a liability account somewhere under assets, and maybe a revenue account under that, and another asset account even further down. In such cases you start to see oddities like accounts appearing in multiple places in a tree-mode report. I have left it this way for now in case it helps with, eg, modelling contra accounts, or combining multiple files each with their own account type declarations. (In that scenario, if we only allowed type declarations on top-level accounts, or only allowed a single account of each type, complications seem likely.) * journal format: periodic transaction rules now require a double space separator. In periodic transaction rules which specify a transaction description or same-line transaction comment, this must be separated from the period expression by two or more spaces, to prevent ambiguous parsing. Eg this will parse correctly as "monthly" thanks to the double space: ~ monthly In 2020 we'll end this monthly transaction. * journal format: exact/complete balance assertions (Samuel May). A stronger kind of balance assertion, written with a double equals sign, asserts an account's complete account balance, not just the balance in one commodity. (But only if it is a single-commodity balance, for now.) Eg: 1/1 (a) A 1 (a) B 1 (a) 0 = A 1 ; commodity A balance assertion, succeeds (a) 0 == A 1 ; complete balance assertion, fails * journal format: account directives now allow whitespace or a comment after the account name * journal format: using ~ for home directory in include directives now works (#896) (Mykola Orliuk) * journal format: prevent misleading parse error messages with cyclic include directives (#853) (Alex Chen) * journal format: transaction modifier multipliers handle total-priced amounts correctly (#928). Multipliers (*N) in transaction modifier rules did not multiply total-priced amounts properly. Now the total prices are also multiplied, keeping the transaction balanced. * journal format: do amount inference/balance assignments/assertions before transaction modifiers (#893, #908) (Jesse Rosenthal) Previously, transaction modifier (auto postings) rules were applied before missing amounts were inferred. This meant amount multipliers could generate too many missing-amount postings, making the transaction unbalanceable (#893). Now, missing amount inference (and balance assignments, and balance assertions, which are interdependent) are done earlier, before transaction modifier rules are applied (#900, #903). Also, we now disallow the combination of balance assignments and transaction modifier rules which both affect the same account, which could otherwise cause confusing balance assertion failures (#912). (Because assignments now generate amounts to satisfy balance assertions before transaction modifier rules are applied (#908).) * journal format: periodic transaction rules are now aware of Y default year directives. (#892) Ie when a default year Y is in effect, they resolve partial or relative dates using Y/1/1 as the reference date, rather than today's date. hledger-ui 1.12 * fix "Any" build error with GHC < 8.4 * error screen: always show error position properly (#904) (Mykola Orliuk) * accounts screen: show correct balances when there's only periodic transactions * drop the --status-toggles flag * periodic transactions and transaction modifiers are always enabled. Rule-based transactions and postings are always generated (--forecast and --auto are always on). Experimental. * escape key resets to flat mode. Flat mode is the default at startup. Probably it should reset to tree mode if --tree was used at startup. * tree mode tweaks: add --tree/-T/-F flags, make flat mode the default, toggle tree mode with T, ensure a visible effect on register screen * hide future txns by default, add --future flag, toggle with F. You may have transactions dated later than today, perhaps piped from print --forecast or recorded in the journal, which you don't want to see except when forecasting. By default, we now hide future transactions, showing "today's balance". This can be toggled with the F key, which is easier than setting a date query. --present and --future flags have been added to set the initial mode. (Experimental. Interactions with date queries have not been explored.) * quick help tweaks; try to show most useful info first * reorganise help dialog, fit content into 80x25 again * styling tweaks; cyan/blue -> white/yellow * less noisy styling in horizontal borders (#838) * register screen: positive amounts: green -> black The green/red scheme helped distinguish the changes column from the black/red balance column, but the default green is hard to read on the pale background in some terminals. Also the changes column is non-bold now. Getting started: ---------------- All install methods are described at http://hledger.org/download . You can download windows binaries, or use a package manager, though in some cases these will install an older hledger version. You can build the latest hledger packages with stack: $ stack install --resolver=lts-12 megaparsec-7.0.4 cassava-megaparsec-2.0.0 config-ini-0.2.3.0 hledger-lib-1.12 hledger-1.12 [hledger-ui-1.12] [hledger-web-1.12] [hledger-api-1.12] or with cabal: $ cabal update && cabal install hledger-1.12 [hledger-ui-1.12] [hledger-web-1.12] [hledger-api-1.12] or with the hledger installer, on systems with bash installed (handy if you don't have a working stack or cabal): $ curl -s https://raw.githubusercontent.com/simonmichael/hledger/master/hledger-install/hledger-install.sh > hledger-install.sh $ less hledger-install.sh # satisfy yourself that the script is safe $ bash hledger-install.sh Some commands to try: $ hledger add # record some transactions, with guidance $ hledger print # show recorded transactions $ hledger balance # show totals by account $ hledger -h # show quick help $ hledger # list available commands $ hledger help # list built-in manuals To get oriented, see the tutorials and manuals at http://hledger.org ; say hello and ask questions in the #hledger IRC channel on Freenode, accessible at http://irc.hledger.org . New users and contributors are always welcome! Best, -Simon From Graham.Hutton at nottingham.ac.uk Tue Dec 4 08:32:38 2018 From: Graham.Hutton at nottingham.ac.uk (Graham Hutton) Date: Tue, 4 Dec 2018 08:32:38 +0000 Subject: [Haskell-cafe] 10 PhD studentships in Nottingham Message-ID: <62F5F3E7-DB13-41D7-AC10-C002AA05E85C@exmail.nottingham.ac.uk> Dear all, The School of Computer Science at the University of Nottingham is seeking applications for 10 fully-funded PhD studentships: https://tinyurl.com/10-phds-2019 Applicants in the area of the Functional Programming Laboratory (https://tinyurl.com/fp-notts) are strongly encouraged! If you are interested in applying, please contact a potential supervisor at least two weeks prior to the 18th January deadline: Thorsten Altenkirch - constructive logic, proof assistants, homotopy type theory, category theory, lambda calculus. Venanzio Capretta - type theory, mathematical logic, corecursive structures, proof assistants, category theory, epistemic logic. Graham Hutton - functional programming, program calculation and transformation, correctness and efficiency, category theory. Henrik Nilsson - functional reactive programming, modelling and simulation, domain-specific languages, probabilistic languages. Best wishes, Graham +-----------------------------------------------------------+ 10 Fully-Funded PhD Studentships School of Computer Science University of Nottingham, UK https://tinyurl.com/10-phds-2019 Applications are invited for up to ten fully-funded PhD studentships in the School of Computer Science at the University of Nottingham, starting on 1 October 2019. The topics for the studentships are open, but should relate to one of the School’s research groups: Agents Lab; Automated Scheduling and Planning; Computer Vision Lab; Data Driven Algorithms, Systems and Design; Functional Programming Lab; Intelligent Modelling and Analysis; Uncertainty in Data and Decision Making; Mixed Reality Lab. The studentships are for a minimum of three years and include a stipend of £14,777 per year and tuition fees. They are open to students of any nationality. Applicants are normally expected to have a first-class MSc or BSc in Computer Science or a related discipline, and must obtain the support of a supervisor in the School prior to submitting their application. Initial contact with supervisors should be made at least two weeks prior to the closing date for applications. Informal enquiries may be addressed to SS-PGR-JC at nottingham.ac.uk. To apply, please submit the following items by email to: Christine.Fletcher at nottingham.ac.uk: (1) a brief covering letter that describes your reasons for wishing to pursue a PhD, your proposed research area and topic, and the name of the potential supervisor whose support you have already secured; (2) a copy of your CV, including your actual or expected degree classes, and results of all University examinations; (3) an extended example of your technical writing, such as a project report or dissertation; (4) contact details for two academic referees. Closing date for applications: Friday 18 January 2019 +-----------------------------------------------------------+ This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please contact the sender and delete the email and attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham. Email communications with the University of Nottingham may be monitored where permitted by law. From polux2001 at gmail.com Tue Dec 4 13:14:25 2018 From: polux2001 at gmail.com (Paul Brauner) Date: Tue, 4 Dec 2018 14:14:25 +0100 Subject: [Haskell-cafe] static analysis of a C-like language In-Reply-To: References: Message-ID: If you're interested I have a draft implemetation of that paper in Haskell that uses monad transformers. There's another one online that uses effect handlers. The original scheme implementation is also available. A caveat: while playing with my implementation I found some issue with the GC as described in the paper and was able to reproduce on the reference implementation: https://github.com/plum-umd/abstracting-definitional-interpreters/issues/82. I'm not knowledgeable enough to understand whether this is a flaw of the approach or something that can be easily fixed. Paul On Thu, Nov 29, 2018 at 3:31 PM Carter Schonwald wrote: > Most parser libraries in Haskell provide facilities for including source > information. > > And then you include in your syntax tree extra fields for those positions. > > Simple as that > > > The paper : > > http://david.darais.com/assets/papers/abstracting-definitional-interpreters/adi.pdf > Is a great reference for how to add a bunch of program analysis features > after you have a working interpreter . Also it’s citations show a bunch of > ways you can Add different flavored of anayses > > On Mon, Nov 26, 2018 at 3:37 PM Olaf Klinke wrote: > >> > Hello Olaf, >> > >> > to me that sounds as if you want to do an abstract interpretation with >> a >> > forward collecting semantics that employs non-relational abstract >> > domains for the primitive data types and summarizes the dimensions of >> > arrays. >> ... >> > I would start by writing a simple interpreter for the language to be >> > analyzed. That way you fix messy details before they bite you, e.g. the >> > order in which submodules are loaded and initialized. >> >> I was hoping not having to write an interpreter (because the language >> author wrote a translation to C++ already), but if that is the way to go, >> I'll do it. As I understand it, the Haskell semantics should contain just >> enough substance so that the errors I am after will cause hiccups in the >> Haskell compiler? That is indeed a compelling approach. >> What this does not address is the question about error reporting: How >> could a translation to Haskell preserve information about scope, source >> position and masking? Can I leverage the ghc API for that? >> >> Regards, >> Olaf >> _______________________________________________ >> Haskell-Cafe mailing list >> To (un)subscribe, modify options or view archives go to: >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> Only members subscribed via the mailman list are allowed to post. > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattei at oca.eu Wed Dec 5 10:35:38 2018 From: mattei at oca.eu (Damien Mattei) Date: Wed, 5 Dec 2018 11:35:38 +0100 Subject: [Haskell-cafe] Fwd: [Haskell-beginners] Database simple-mysql In-Reply-To: <5C07A88A.6030706@oca.eu> References: <5C07A88A.6030706@oca.eu> Message-ID: <5C07A9FA.6090605@oca.eu> -------- Message transféré -------- Sujet : [Haskell-beginners] Database simple-mysql Date : Wed, 5 Dec 2018 11:29:30 +0100 De : Damien Mattei Répondre à : The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell Pour : beginners at haskell.org why does this works: let name = "'A 20'" bd_rows <- query_ conn "select `N° BD` from sidonie.Coordonnées where Nom = 'A 20'" putStrLn $ show bd_rows putStrLn $ show name i got: [Only {fromOnly = "-04.3982"}] "'A 20'" -04.3982 but not with this: bd_rows <- query conn "select `N° BD` from sidonie.Coordonnées where Nom = ?" (Only (name::String)) i got an empty result: [] ... ??? -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From ietf-dane at dukhovni.org Wed Dec 5 15:51:53 2018 From: ietf-dane at dukhovni.org (Viktor Dukhovni) Date: Wed, 5 Dec 2018 10:51:53 -0500 Subject: [Haskell-cafe] Fwd: [Haskell-beginners] Database simple-mysql In-Reply-To: <5C07A9FA.6090605@oca.eu> References: <5C07A88A.6030706@oca.eu> <5C07A9FA.6090605@oca.eu> Message-ID: <186DEDC5-5DF4-403B-A0DB-CC65E1A559BF@dukhovni.org> > why does this works: > let name = "'A 20'" > > bd_rows <- query_ conn "select `N° BD` from sidonie.Coordonnées where > Nom = 'A 20'" The "Nom" equality constraint was the String: <2><0> > but not with this: > > bd_rows <- query conn "select `N° BD` from sidonie.Coordonnées where > Nom = ?" (Only (name::String)) No additional quoting is required or appropriate with prepared statements. The "Nom" constraint in this case was incorrectly: <'><2><0><'> This is not Haskell-specific. The fact that prepared statement parameters don't use or require quoting is an important safety feature (no SQL-injection with prepared statements). Every language that offers SQL bindings with prepared statement support behaves this way. -- Viktor. From branimir.maksimovic at gmail.com Thu Dec 6 04:03:13 2018 From: branimir.maksimovic at gmail.com (Branimir Maksimovic) Date: Thu, 6 Dec 2018 05:03:13 +0100 Subject: [Haskell-cafe] ghc install from source fails Message-ID: <42a43b52-1a74-8241-70c3-f18b76952e9a@gmail.com> I have this problem when installin ghc from git: nstalling library in /home/bmaxa/ghc/lib/ghc-8.7.20181205/ghc-prim-0.5.3 dist-install/build/HSghc-prim-0.5.3.p_o: copyFile: does not exist (No such file or directory) p_o files are missing, and install fails. google does not helps. Can't find any option to suppress installation of p_o files or to build them. Thanks, Branimir. From b.lijnse at cs.ru.nl Thu Dec 6 08:55:14 2018 From: b.lijnse at cs.ru.nl (Bas Lijnse) Date: Thu, 6 Dec 2018 09:55:14 +0100 Subject: [Haskell-cafe] Fwd: [Fp-nl] FP-Day 2019 In-Reply-To: <804c3352-666c-c979-d7f5-4e00bab46033@baslijnse.nl> References: <804c3352-666c-c979-d7f5-4e00bab46033@baslijnse.nl> Message-ID: <2d2346fb-882f-adbe-78e9-05ef19b641f1@cs.ru.nl> Hi Haskell-Cafe This is probably only relevant for (but not exclusively for) the Haskellers from the Netherlands. I just wanted to make you aware of the upcoming Dutch FP-Day on January 11, 2019. Best, Bas -------- Forwarded Message -------- Subject: [Fp-nl] FP-Day 2019 Date: Mon, 3 Dec 2018 20:24:37 +0100 From: Bas Lijnse via Fp-nl Reply-To: Bas Lijnse To: fp-nl at lists.science.uu.nl Dear Fellow Functional Programmers, As the end of 2018 is rapidly approaching, you may be wondering when and where the Dutch FP-Day 2019 will be. It is traditionally organized one of the first Fridays of the new year after all. We have the pleasure to announce that it will be on *Friday Jan 11, 2019* in *Breda*. It will be hosted by the Netherlands Defence Academy at the "Trip van Zoutlandt Kazerne". More information about registration, the program and other details can be found at: https://wiki.clean.cs.ru.nl/NL-FP_dag_2019 You can register, and/or propose a talk by e-mailing us directly (because of the venue, registration is mandatory). Best regards, Bas Lijnse and Jan Martin Jansen b.lijnse at mindef.nl / b.lijnse at cs.ru.nl jm.jansen.04 at mindef.nl / jan.martin.jansen at gmail.com PS. Apologies if you receive this e-mail twice. It came to our attention that an earlier attempt of sending this e-mail to this list failed somehow. _______________________________________________ Fp-nl mailing list Fp-nl at lists.science.uu.nl https://mailman.science.uu.nl/mailman/listinfo/fp-nl -------------- next part -------------- An HTML attachment was scrubbed... URL: From danburton.email at gmail.com Thu Dec 6 21:26:18 2018 From: danburton.email at gmail.com (Dan Burton) Date: Thu, 6 Dec 2018 16:26:18 -0500 Subject: [Haskell-cafe] [Haskell] Guidelines for respectful communication In-Reply-To: References: Message-ID: Thank you, Simon. My experience with the Haskell community has been quite positive over the years. I am continually pleased to see community leaders make an intentional effort to maintain the Haskell community's reputation of kindness, helpfulness, and inclusiveness. Say what you will about design-by-committee processes, but the growing Haskell community -- with the increasing diversity that comes with that -- is refining, extending, and supporting the language in new and interesting ways. By intentionally and explicitly embracing these patterns of respectful communication, you facilitate the continued growth and improvement of the language. Thank you again for the careful thought you have put into the topic of communication. Your effort is greatly appreciated! -- Dan Burton On Thu, Dec 6, 2018 at 5:35 AM Simon Peyton Jones via Haskell < haskell at haskell.org> wrote: > Friends > As many of you will know, I have been concerned for several years about > the standards of discourse in the Haskell community. I think things have > improved since the period that drove me to write my Respect email< > https://mail.haskell.org/pipermail/haskell/2016-September/024995.html>, > but it's far from secure. > We discussed this at a meeting of the GHC Steering Committee< > https://github.com/ghc-proposals/ghc-proposals> at ICFP in September, and > many of us have had related discussions since. Arising out of that > conversation, the GHC Steering Committee has decided to adopt these > Guidelines for respectful communication< > https://github.com/ghc-proposals/ghc-proposals/blob/master/GRC.rst> > > We are not trying to impose these guidelines on members of the Haskell > community generally. Rather, we are adopting them for ourselves, as a > signal that we seek high standards of discourse in the Haskell community, > and are willing to publicly hold ourselves to that standard, in the hope > that others may choose to follow suit. > We are calling them "guidelines for respectful communication" rather than > a "code of conduct", because we want to encourage good communication, > rather than focus on bad behaviour. Richard Stallman's recent post< > https://lwn.net/Articles/769167/> about the new GNU Kind Communication > Guidelines expresses > the same idea. > Meanwhile, the Stack community is taking a similar approach< > https://www.snoyman.com/blog/2018/11/proposal-stack-coc>. > Our guidelines are not set in stone; you can comment here< > https://github.com/ghc-proposals/ghc-proposals/commit/373044b5a78519071b9a24b3681cfd1af06e57e0>. > Perhaps they can evolve so that other Haskell committees (or even > individuals) feel able to adopt them. > The Haskell community is such a rich collection of intelligent, > passionate, and committed people. Thank you -- I love you all! > Simon > > > > _______________________________________________ > Haskell mailing list > Haskell at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell > -------------- next part -------------- An HTML attachment was scrubbed... URL: From johnw at newartisans.com Fri Dec 7 00:06:12 2018 From: johnw at newartisans.com (John Wiegley) Date: Thu, 06 Dec 2018 16:06:12 -0800 Subject: [Haskell-cafe] [Haskell] Guidelines for respectful communication In-Reply-To: (Dan Burton's message of "Thu, 6 Dec 2018 16:26:18 -0500") References: Message-ID: >>>>> "DB" == Dan Burton writes: DB> Thank you again for the careful thought you have put into the topic of DB> communication. Your effort is greatly appreciated! Indeed, any standard that is good enough for Simon is one I'll gladly adhere to as well. -- John Wiegley GPG fingerprint = 4710 CF98 AF9B 327B B80F http://newartisans.com 60E1 46C4 BD1A 7AC1 4BA2 From daniel.huebleitner at student.tuwien.ac.at Sat Dec 8 00:38:52 2018 From: daniel.huebleitner at student.tuwien.ac.at (daniel huebleitner) Date: Sat, 8 Dec 2018 01:38:52 +0100 Subject: [Haskell-cafe] Stack data structure Message-ID: <3d80eb46-0214-6908-a715-a8615db31eae@student.tuwien.ac.at> I am a graduate student in theoretical computer science playing around with haskell for the past year or so. I wrote a Stack Data structure today and would like to get some feedback from more experienced haskellers if possible. I know its a really simple thing to write. But the implementation I found on hackage wasn't what I was looking for. I haven't wrote unit tests yet, but it should behave as expected. Thanks in advance. Kind regards. Daniel -------------- next part -------------- A non-text attachment was scrubbed... Name: Stack.hs Type: text/x-haskell Size: 2168 bytes Desc: not available URL: From javran.c at gmail.com Sat Dec 8 01:47:44 2018 From: javran.c at gmail.com (Javran Cheng) Date: Fri, 7 Dec 2018 17:47:44 -0800 Subject: [Haskell-cafe] version sorting? Message-ID: Hi Cafe, I'm wondering if there's any existing packages that do "version sorting": as an example, for a list like: ["foo-10.20", "foo-1.2", "foo-2.100", "foo-1.12"] I'd like the result to be: ["foo-1.2", "foo-1.12", "foo-2.100", "foo-10.20"] I could think of an implementation that turns String elements of a list into [Either Int String] by grouping consecutive chunks using span and isDigit and then do a sortOn: versionSort :: [String] -> [String] versionSort = sortOn brkND where tr f g (x,y) = f x : g y -- ND for non-digits brkND = tr Right brkD . span (not . isDigit) brkD = tr (Left . read @Int) brkND . span isDigit (side question: does the helper function tr I defined above have a commonly known name?) just wondering if there are more sophisticated solutions available. Best, Javran -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Sat Dec 8 07:18:21 2018 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Sat, 8 Dec 2018 14:18:21 +0700 Subject: [Haskell-cafe] Stack data structure In-Reply-To: <3d80eb46-0214-6908-a715-a8615db31eae@student.tuwien.ac.at> References: <3d80eb46-0214-6908-a715-a8615db31eae@student.tuwien.ac.at> Message-ID: Hi Daniel, Could you say what it was that you are looking for that you did not find in existing libraries? A cursory glance of your code did not reveal anything striking. Also the traditional way of discussing code on this list is to paste it in the email, literate style if you wish, and not as file attachments. Github gists and lpaste have also seen use but there is nothing like the immediacy of code in email. To that end, I have pasted your code below for the benefit of all. Best, Kim-Ee module Data.Stack ( Stack , empty , size , push, push' , peek , pop, pop_, _pop , turn , null , fromList, toList , over, under ) where import qualified Data.Sequence as S import qualified Data.Foldable as F import Prelude hiding (null) data Stack a = Stack (S.Seq a) deriving (Eq, Read, Show) -- | returns the empty stack -- | O(1) empty :: Stack a empty = Stack S.empty -- | returns the stack size -- | O(1) size :: Stack a -> Int size (Stack items) = S.length items -- | push an element on the stack -- | O(1) push :: Stack a -> a -> Stack a push (Stack items) item = Stack (item S.<| items) -- | push with its arguments flipped -- | O(1) push' :: a -> Stack a -> Stack a push' = flip push -- | returns the topmost element -- | O(1) peek :: Stack a -> Maybe a peek (Stack items) = items S.!? 0 -- | returns the topmost element or nothing and the new stack -- | O(1) pop :: Stack a -> (Stack a, Maybe a) pop (Stack items) = (Stack $ S.drop 1 items, items S.!? 0) -- | return the stack without the topmost element -- | O(1) pop_ :: Stack a -> (Stack a) pop_ stack = fst $ pop stack -- | returns the topmost element or nothing -- | O(1) _pop :: Stack a -> Maybe a _pop stack = snd $ pop stack -- | turns the stack upside down -- | O(n) turn :: Stack a -> Stack a turn (Stack items) = Stack (S.reverse items) -- | returns true if it is the empty stack -- | O(1) null :: Stack a -> Bool null (Stack items) = S.null items -- | creates a stack from a list -- | O(n) fromList :: [a] -> Stack a fromList list = Stack $ S.fromList list -- | returns a list from the stack -- | O(n) toList :: Stack a -> [a] toList (Stack items) = F.toList items -- | puts the first stack onto the second stack -- | O(log(min(a,b))) over :: Stack a -> Stack a -> Stack a (Stack a) `over` (Stack b) = Stack (a S.>< b) -- | puts the first stack under the second stack -- | O(log(min(a,b))) under :: Stack a -> Stack a -> Stack a (Stack a) `under` (Stack b) = Stack (b S.>< a) On Saturday, December 8, 2018, daniel huebleitner < daniel.huebleitner at student.tuwien.ac.at> wrote: > I am a graduate student in theoretical computer science playing around > with haskell for the past year or so. I wrote a Stack Data structure today > and would like to get some feedback from more experienced haskellers if > possible. I know its a really simple thing to write. But the implementation > I found on hackage wasn't what I was looking for. I haven't wrote unit > tests yet, but it should behave as expected. > > Thanks in advance. > > Kind regards. > > Daniel > > > > -- -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk Sat Dec 8 08:23:34 2018 From: tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk (Tom Ellis) Date: Sat, 8 Dec 2018 08:23:34 +0000 Subject: [Haskell-cafe] version sorting? In-Reply-To: References: Message-ID: <20181208082334.fam6oxx57rwjtsxb@weber> On Fri, Dec 07, 2018 at 05:47:44PM -0800, Javran Cheng wrote: > I'm wondering if there's any existing packages that do "version sorting": > as an example, for a list like: There's this https://hackage.haskell.org/package/versions-3.5.0/docs/Data-Versions.html and Versioning has an Ord instance. I don't think it deals with the package name though. It should be easy to combine something simple with versioning' though https://hackage.haskell.org/package/versions-3.5.0/docs/Data-Versions.html#v:versioning-39- From fa-ml at ariis.it Sat Dec 8 10:38:15 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 8 Dec 2018 11:38:15 +0100 Subject: [Haskell-cafe] version sorting? In-Reply-To: References: Message-ID: <20181208103815.2rilpreha2uamnlx@x60s.casa> Hello Jarvan, On Fri, Dec 07, 2018 at 05:47:44PM -0800, Javran Cheng wrote: > I'm wondering if there's any existing packages that do "version sorting": > as an example, for a list like: https://hackage.haskell.org/package/natural-sort λ> :m +Algorithms.NaturalSort λ> :m +Data.List λ> sortBy (Algorithms.NaturalSort.compare) ["foo-10.20", "foo-1.2", "foo-2.100", "foo-1.12"] ["foo-1.2","foo-1.12","foo-2.100","foo-10.20"] From fa-ml at ariis.it Sat Dec 8 11:02:50 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 8 Dec 2018 12:02:50 +0100 Subject: [Haskell-cafe] Stack data structure In-Reply-To: <3d80eb46-0214-6908-a715-a8615db31eae@student.tuwien.ac.at> References: <3d80eb46-0214-6908-a715-a8615db31eae@student.tuwien.ac.at> Message-ID: <20181208110250.6yaovnfyhcen24mm@x60s.casa> Hello Daniel, On Sat, Dec 08, 2018 at 01:38:52AM +0100, daniel huebleitner wrote: > I am a graduate student in theoretical computer science playing around with > haskell for the past year or so. I wrote a Stack Data structure today and > would like to get some feedback from more experienced haskellers if > possible. The (small) tings I noticed: - For haddock purposes, comments should start with |, but only the first line. I.e.: -- | returns the empty stack -- O(1) - `data Stack a` could well become `newtype Stack a` since there is only one constructor/field in it. - hlint picks up a redundant pair of brackets on line 51. I personally don't mind attached code but maybe the `text/x-haskell` directive isn't handled gracefully by all clients. I played around with it on ghci and everything seemed fine! From monkleyon at gmail.com Sat Dec 8 13:16:49 2018 From: monkleyon at gmail.com (MarLinn) Date: Sat, 8 Dec 2018 14:16:49 +0100 Subject: [Haskell-cafe] version sorting? In-Reply-To: References: Message-ID: <957030a8-cbaf-4f55-91cf-9688af742cc6@gmail.com> > versionSort :: [String] -> [String] > versionSort = sortOn brkND >   where >     tr f g (x,y) = f x : g y >     -- ND for non-digits >     brkND = tr Right brkD . span (not . isDigit) >     brkD = tr (Left . read @Int) brkND . span isDigit > > (side question: does the helper function tr I defined above have a > commonly known name?) I don't think so, but that's just because you made the cut at a weird point. It's very close to (***) from Control.Arrow, Data.Tuple.Extra, Data.Profunctor, and other libraries, also known as bimap in Data.Bifunctor and in the lens package. Rewriting your functions to tease it out even more (not tested): versionSort :: [String] -> [String] versionSort = sortOn gatherNonDigits  where  gatherAll predicate gather continue = uncurry (:) . (gather *** continue) . span predicate  -- 'NonDigits' for non-digits       gatherNonDigits = gatherAll (not . isDigit) wrapNonDigits gatherDigits     gatherDigits  = gatherAll isDigit wrapDigits gatherNonDigits  wrapNonDigits = Right wrapDigits = Left . read @Int -------------- next part -------------- An HTML attachment was scrubbed... URL: From iustin at k1024.org Sat Dec 8 13:31:25 2018 From: iustin at k1024.org (Iustin Pop) Date: Sat, 8 Dec 2018 14:31:25 +0100 Subject: [Haskell-cafe] version sorting? In-Reply-To: <20181208103815.2rilpreha2uamnlx@x60s.casa> References: <20181208103815.2rilpreha2uamnlx@x60s.casa> Message-ID: <20181208133125.GD4966@teal.hq.k1024.org> On 2018-12-08 11:38:15, Francesco Ariis wrote: > Hello Jarvan, > > On Fri, Dec 07, 2018 at 05:47:44PM -0800, Javran Cheng wrote: > > I'm wondering if there's any existing packages that do "version sorting": > > as an example, for a list like: > > https://hackage.haskell.org/package/natural-sort > > λ> :m +Algorithms.NaturalSort > λ> :m +Data.List > λ> sortBy (Algorithms.NaturalSort.compare) ["foo-10.20", "foo-1.2", "foo-2.100", "foo-1.12"] > ["foo-1.2","foo-1.12","foo-2.100","foo-10.20"] Does it really sort 1.2 before 1.12? (or is it just a copy-paste error) curious, iustin From fa-ml at ariis.it Sat Dec 8 14:08:20 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 8 Dec 2018 15:08:20 +0100 Subject: [Haskell-cafe] version sorting? In-Reply-To: <20181208133125.GD4966@teal.hq.k1024.org> References: <20181208103815.2rilpreha2uamnlx@x60s.casa> <20181208133125.GD4966@teal.hq.k1024.org> Message-ID: <20181208140820.4ifb64ttgvxwlwni@x60s.casa> On Sat, Dec 08, 2018 at 02:31:25PM +0100, Iustin Pop wrote: > Does it really sort 1.2 before 1.12? (or is it just a copy-paste error) It does, hence the name of the library! From iustin at k1024.org Sat Dec 8 14:09:43 2018 From: iustin at k1024.org (Iustin Pop) Date: Sat, 8 Dec 2018 15:09:43 +0100 Subject: [Haskell-cafe] version sorting? In-Reply-To: <20181208140820.4ifb64ttgvxwlwni@x60s.casa> References: <20181208103815.2rilpreha2uamnlx@x60s.casa> <20181208133125.GD4966@teal.hq.k1024.org> <20181208140820.4ifb64ttgvxwlwni@x60s.casa> Message-ID: <20181208140943.GB28859@teal.hq.k1024.org> On 2018-12-08 15:08:20, Francesco Ariis wrote: > On Sat, Dec 08, 2018 at 02:31:25PM +0100, Iustin Pop wrote: > > Does it really sort 1.2 before 1.12? (or is it just a copy-paste error) > > It does, hence the name of the library! Apologies - given the ".12", I implicitly translated ".2" as ".20". Just a slow day :) iustin From fa-ml at ariis.it Sat Dec 8 14:33:35 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 8 Dec 2018 15:33:35 +0100 Subject: [Haskell-cafe] version sorting? In-Reply-To: <20181208140943.GB28859@teal.hq.k1024.org> References: <20181208103815.2rilpreha2uamnlx@x60s.casa> <20181208133125.GD4966@teal.hq.k1024.org> <20181208140820.4ifb64ttgvxwlwni@x60s.casa> <20181208140943.GB28859@teal.hq.k1024.org> Message-ID: <20181208143335.ufx263kkynwa6k6i@x60s.casa> On Sat, Dec 08, 2018 at 03:09:43PM +0100, Iustin Pop wrote: > Apologies - given the ".12", I implicitly translated ".2" as ".20". Just > a slow day :) No worries, I have bitten by "0.x/0.x0" more times than I am willing to admit :P -F From sergueyz at gmail.com Sat Dec 8 14:33:35 2018 From: sergueyz at gmail.com (Serguey Zefirov) Date: Sat, 8 Dec 2018 17:33:35 +0300 Subject: [Haskell-cafe] Stack data structure In-Reply-To: <3d80eb46-0214-6908-a715-a8615db31eae@student.tuwien.ac.at> References: <3d80eb46-0214-6908-a715-a8615db31eae@student.tuwien.ac.at> Message-ID: The list as usually constructed (head and tail) is a stack. сб, 8 дек. 2018 г. в 03:43, daniel huebleitner < daniel.huebleitner at student.tuwien.ac.at>: > I am a graduate student in theoretical computer science playing around > with haskell for the past year or so. I wrote a Stack Data structure > today and would like to get some feedback from more experienced > haskellers if possible. I know its a really simple thing to write. But > the implementation I found on hackage wasn't what I was looking for. I > haven't wrote unit tests yet, but it should behave as expected. > > Thanks in advance. > > Kind regards. > > Daniel > > > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From javran.c at gmail.com Sat Dec 8 19:39:22 2018 From: javran.c at gmail.com (Javran Cheng) Date: Sat, 8 Dec 2018 11:39:22 -0800 Subject: [Haskell-cafe] version sorting? In-Reply-To: <20181208143335.ufx263kkynwa6k6i@x60s.casa> References: <20181208103815.2rilpreha2uamnlx@x60s.casa> <20181208133125.GD4966@teal.hq.k1024.org> <20181208140820.4ifb64ttgvxwlwni@x60s.casa> <20181208140943.GB28859@teal.hq.k1024.org> <20181208143335.ufx263kkynwa6k6i@x60s.casa> Message-ID: Thanks for the suggestion! natural-sort looks like what I want - I've just taken a quick look and the algorithm is almost the same if I'm not mistaken. also thanks MarLinn - it's just that as I wrote I realized I've been implemented "tr" over and over again so there might be a common name for it. I do recognize there's a (***) out there and hoogling (a, [a]) -> [a] doesn't yield any function of interest., didn't bother to go any further to see the rest of it is just a curried (:). I'd still prefer "tr" though as for me if you think it as a rewrite rule, it's more readable than having a chain of function composition. Cheers! On Sat, Dec 8, 2018 at 6:34 AM Francesco Ariis wrote: > On Sat, Dec 08, 2018 at 03:09:43PM +0100, Iustin Pop wrote: > > Apologies - given the ".12", I implicitly translated ".2" as ".20". Just > > a slow day :) > > No worries, I have bitten by "0.x/0.x0" more times than I am willing to > admit :P > -F > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -- Javran (Fang) Cheng -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian at zenhack.net Sat Dec 8 19:46:25 2018 From: ian at zenhack.net (Ian Denhardt) Date: Sat, 08 Dec 2018 14:46:25 -0500 Subject: [Haskell-cafe] Stack data structure In-Reply-To: References: <3d80eb46-0214-6908-a715-a8615db31eae@student.tuwien.ac.at> Message-ID: <154429838594.885.12266862150634422821@localhost> Quoting Serguey Zefirov (2018-12-08 09:33:35) > The list as usually constructed (head and tail) is a stack. This was my reaction as well; except for the over and under operations, everything in the file would have as-good or better asymptotic complexity as a simple list, and probably better constant factors too. The docs for Data.Sequence even say: > Note that sequences are typically slower than lists when using only > operations for which they have the same big-(O) complexity: sequences > make rather mediocre stacks! It would also likely be more readable to use a list, in that every Haskeller knows the list APIs, whereas Data.Sequence is less likely to be familiar. TBH, most cases where I would want a stack I wouldn't even bother with the extra layer of abstraction over lists -- I'd probably use the directly. You mention being unsatisfied with the existing libraries -- what was your use case? From sergueyz at gmail.com Sat Dec 8 21:23:14 2018 From: sergueyz at gmail.com (Serguey Zefirov) Date: Sun, 9 Dec 2018 00:23:14 +0300 Subject: [Haskell-cafe] Stack data structure In-Reply-To: <154429838594.885.12266862150634422821@localhost> References: <3d80eb46-0214-6908-a715-a8615db31eae@student.tuwien.ac.at> <154429838594.885.12266862150634422821@localhost> Message-ID: I once improved Seq-based code by changing them to lists. The improvement was about 10x in both memory and speed and all can be attributed to just constant factors. When I saw the same error again above I can't help myself. сб, 8 дек. 2018 г. в 22:48, Ian Denhardt : > Quoting Serguey Zefirov (2018-12-08 09:33:35) > > The list as usually constructed (head and tail) is a stack. > > This was my reaction as well; except for the over and under operations, > everything in the file would have as-good or better asymptotic > complexity as a simple list, and probably better constant factors too. > The docs for Data.Sequence even say: > > > Note that sequences are typically slower than lists when using only > > operations for which they have the same big-(O) complexity: sequences > > make rather mediocre stacks! > > It would also likely be more readable to use a list, in that every > Haskeller knows the list APIs, whereas Data.Sequence is less likely to > be familiar. > > TBH, most cases where I would want a stack I wouldn't even bother with > the extra layer of abstraction over lists -- I'd probably use the > directly. > > You mention being unsatisfied with the existing libraries -- what was > your use case? > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffbrown.the at gmail.com Sun Dec 9 00:45:49 2018 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Sat, 8 Dec 2018 19:45:49 -0500 Subject: [Haskell-cafe] Faster set intersections? Message-ID: The following expressions both cause GHCI to hang: > S.intersection (S.fromList [1,2]) (S.fromList [1..]) fromList ^CInterrupted. > S.intersection (S.fromList [1..]) (S.fromList [1,2]) fromList ^CInterrupted. > Is there a smarter way to take the intersection of sets when at least one of them is small (but I don't know which one that is)? -- Jeff Brown | Jeffrey Benjamin Brown Website | Facebook | LinkedIn (spammy, so I often miss messages here) | Github -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Sun Dec 9 00:51:13 2018 From: allbery.b at gmail.com (Brandon Allbery) Date: Sat, 8 Dec 2018 19:51:13 -0500 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: I suspect not. Maybe with fromAscList or fromDistinctAscList so it can know the list won't pop a smaller (here, duplicate) value on it, if it's lazy enough (I haven't checked). Lists don't record that they were generated from enumerations. On Sat, Dec 8, 2018 at 7:46 PM Jeffrey Brown wrote: > The following expressions both cause GHCI to hang: > > > S.intersection (S.fromList [1,2]) (S.fromList [1..]) > fromList ^CInterrupted. > > S.intersection (S.fromList [1..]) (S.fromList [1,2]) > fromList ^CInterrupted. > > > > Is there a smarter way to take the intersection of sets when at least one > of them is small (but I don't know which one that is)? > > -- > Jeff Brown | Jeffrey Benjamin Brown > Website | Facebook > | LinkedIn > (spammy, so I often > miss messages here) | Github > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -- brandon s allbery kf8nh allbery.b at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jmaessen at alum.mit.edu Sun Dec 9 02:35:27 2018 From: jmaessen at alum.mit.edu (Jan-Willem Maessen) Date: Sat, 8 Dec 2018 21:35:27 -0500 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: On Sat, Dec 8, 2018 at 7:46 PM Jeffrey Brown wrote: > The following expressions both cause GHCI to hang: > > > S.intersection (S.fromList [1,2]) (S.fromList [1..]) > fromList ^CInterrupted. > > S.intersection (S.fromList [1..]) (S.fromList [1,2]) > fromList ^CInterrupted. > > > > Is there a smarter way to take the intersection of sets when at least one > of them is small (but I don't know which one that is)? > Taking the intersection of already-constructed, finite sets is very fast if one of them is small (should be O(n lg m) where n is the size of the smaller set and m the size of the larger one). However, Data.Set doesn't handle infinite sets as it tries to construct balanced trees and is strict in the keys. Even fromAscList won't help you here. To represent infinite (or bigger than you actually want to construct) sets you'll likely need to roll your own custom representation, and I suspect it will in general need to either have limitations on the key space or worse asymptotic performance. That said, you can often get the behavior you're looking for by representing big sets by a membership predicate and using filter. Here's an (untested) example of the right sort of thing: data MySet k = Pred (k -> Bool) | Concrete (S.Set k) intersection (Pred a) (Pred b) = Pred (\k -> a k && b k) intersection (Concrete a) (Pred b) = Concrete (S.filter b a) intersection (Pred a) (Concrete b) = Concrete (S.filter a b) intersection (Concrete a) (Concrete b) = Concrete (S.intersection a b) Note that a concrete set "concretizes" anything it touches. Don't take unions of these sets, though, it'll just be a mess. -Jan-Willem Maessen > > -- > Jeff Brown | Jeffrey Benjamin Brown > Website | Facebook > | LinkedIn > (spammy, so I often > miss messages here) | Github > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From david.feuer at gmail.com Sun Dec 9 02:36:32 2018 From: david.feuer at gmail.com (David Feuer) Date: Sat, 8 Dec 2018 21:36:32 -0500 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: Not like that, no. The Set type is explicitly for *finite* sets only. fromList [1..] is bottom and will run out of memory. You'd need a *very* different implementation to be able to support infinite sets at all, and even then you'd only catch certain special cases. On Sat, Dec 8, 2018, 7:46 PM Jeffrey Brown The following expressions both cause GHCI to hang: > > > S.intersection (S.fromList [1,2]) (S.fromList [1..]) > fromList ^CInterrupted. > > S.intersection (S.fromList [1..]) (S.fromList [1,2]) > fromList ^CInterrupted. > > > > Is there a smarter way to take the intersection of sets when at least one > of them is small (but I don't know which one that is)? > > -- > Jeff Brown | Jeffrey Benjamin Brown > Website | Facebook > | LinkedIn > (spammy, so I often > miss messages here) | Github > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ivan.miljenovic at gmail.com Sun Dec 9 08:21:47 2018 From: ivan.miljenovic at gmail.com (Ivan Lazar Miljenovic) Date: Sun, 9 Dec 2018 16:21:47 +0800 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: On Dec 9, 2018 11:36 AM, "Jan-Willem Maessen" wrote: Note that a concrete set "concretizes" anything it touches. Don't take unions of these sets, though, it'll just be a mess. Won't a union just be the same as intersection but using || instead of && ? -Jan-Willem Maessen > > -- > Jeff Brown | Jeffrey Benjamin Brown > Website | Facebook > | LinkedIn > (spammy, so I often > miss messages here) | Github > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. > _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From olf at aatal-apotheke.de Sun Dec 9 16:38:11 2018 From: olf at aatal-apotheke.de (Olaf Klinke) Date: Sun, 9 Dec 2018 17:38:11 +0100 Subject: [Haskell-cafe] Faster set intersections? Message-ID: > Note that a concrete set "concretizes" anything it touches. Don't take > unions of these sets, though, it'll just be a mess. > > > Won't a union just be the same as intersection but using || instead of && ? > > > -Jan-Willem Maessen Unions of predicates and concrete sets are easy, thanks to Set.member: union (Pred p) (Concrete s) = Pred (\k -> p k || member k s) What you can not do, of course, is enumerate and fold these sets. There is a set type [1] which supports a litte bit more: Set a = Maybe ((a -> Bool) -> a) It has unions, intersections and a Monad instance and can represent infinite sets. If the base type has an Ord instance, the set can be enumerated. If the base type has an Eq instance, so has (Set a). Some functions usually implemented using Foldable are also possible, e.g. minimum and maximum. Caveat: Performance can be poor, depending on how the function inside the set was defined. Cheers, Olaf [1] http://hackage.haskell.org/package/infinite-search From siddu.druid at gmail.com Sun Dec 9 18:31:56 2018 From: siddu.druid at gmail.com (Siddharth Bhat) Date: Mon, 10 Dec 2018 00:01:56 +0530 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: I don't understand, how does (a -> Bool) -> a model a set? Thanks Siddharth On Sun, 9 Dec, 2018, 22:08 Olaf Klinke, wrote: > > Note that a concrete set "concretizes" anything it touches. Don't take > > unions of these sets, though, it'll just be a mess. > > > > > > Won't a union just be the same as intersection but using || instead of > && ? > > > > > > -Jan-Willem Maessen > > Unions of predicates and concrete sets are easy, thanks to Set.member: > > union (Pred p) (Concrete s) = Pred (\k -> p k || member k s) > > What you can not do, of course, is enumerate and fold these sets. > There is a set type [1] which supports a litte bit more: > > Set a = Maybe ((a -> Bool) -> a) > > It has unions, intersections and a Monad instance and can represent > infinite sets. If the base type has an Ord instance, the set can be > enumerated. If the base type has an Eq instance, so has (Set a). Some > functions usually implemented using Foldable are also possible, e.g. > minimum and maximum. > Caveat: Performance can be poor, depending on how the function inside the > set was defined. > > Cheers, > Olaf > > [1] http://hackage.haskell.org/package/infinite-search > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -- Sending this from my phone, please excuse any typos! -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Sun Dec 9 18:36:06 2018 From: allbery.b at gmail.com (Brandon Allbery) Date: Sun, 9 Dec 2018 13:36:06 -0500 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: Naïvely, a set implemented as a predicate determining membership? On Sun, Dec 9, 2018 at 1:32 PM Siddharth Bhat wrote: > I don't understand, how does > > (a -> Bool) -> a > > model a set? > > Thanks > Siddharth > > On Sun, 9 Dec, 2018, 22:08 Olaf Klinke, wrote: > >> > Note that a concrete set "concretizes" anything it touches. Don't take >> > unions of these sets, though, it'll just be a mess. >> > >> > >> > Won't a union just be the same as intersection but using || instead of >> && ? >> > >> > >> > -Jan-Willem Maessen >> >> Unions of predicates and concrete sets are easy, thanks to Set.member: >> >> union (Pred p) (Concrete s) = Pred (\k -> p k || member k s) >> >> What you can not do, of course, is enumerate and fold these sets. >> There is a set type [1] which supports a litte bit more: >> >> Set a = Maybe ((a -> Bool) -> a) >> >> It has unions, intersections and a Monad instance and can represent >> infinite sets. If the base type has an Ord instance, the set can be >> enumerated. If the base type has an Eq instance, so has (Set a). Some >> functions usually implemented using Foldable are also possible, e.g. >> minimum and maximum. >> Caveat: Performance can be poor, depending on how the function inside the >> set was defined. >> >> Cheers, >> Olaf >> >> [1] http://hackage.haskell.org/package/infinite-search >> _______________________________________________ >> Haskell-Cafe mailing list >> To (un)subscribe, modify options or view archives go to: >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> Only members subscribed via the mailman list are allowed to post. > > -- > Sending this from my phone, please excuse any typos! > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -- brandon s allbery kf8nh allbery.b at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk Sun Dec 9 18:40:35 2018 From: tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk (Tom Ellis) Date: Sun, 9 Dec 2018 18:40:35 +0000 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: <20181209184035.557ffghpq77q4gvr@weber> That would be `a -> Bool`. On Sun, Dec 09, 2018 at 01:36:06PM -0500, Brandon Allbery wrote: > Naïvely, a set implemented as a predicate determining membership? > > On Sun, Dec 9, 2018 at 1:32 PM Siddharth Bhat wrote: > > > I don't understand, how does > > > > (a -> Bool) -> a > > > > model a set? > > > > Thanks > > Siddharth > > > > On Sun, 9 Dec, 2018, 22:08 Olaf Klinke, wrote: > > > >> > Note that a concrete set "concretizes" anything it touches. Don't take > >> > unions of these sets, though, it'll just be a mess. > >> > > >> > > >> > Won't a union just be the same as intersection but using || instead of > >> && ? > >> > > >> > > >> > -Jan-Willem Maessen > >> > >> Unions of predicates and concrete sets are easy, thanks to Set.member: > >> > >> union (Pred p) (Concrete s) = Pred (\k -> p k || member k s) > >> > >> What you can not do, of course, is enumerate and fold these sets. > >> There is a set type [1] which supports a litte bit more: > >> > >> Set a = Maybe ((a -> Bool) -> a) > >> > >> It has unions, intersections and a Monad instance and can represent > >> infinite sets. If the base type has an Ord instance, the set can be > >> enumerated. If the base type has an Eq instance, so has (Set a). Some > >> functions usually implemented using Foldable are also possible, e.g. > >> minimum and maximum. > >> Caveat: Performance can be poor, depending on how the function inside the > >> set was defined. > >> > >> Cheers, > >> Olaf > >> > >> [1] http://hackage.haskell.org/package/infinite-search > >> _______________________________________________ > >> Haskell-Cafe mailing list > >> To (un)subscribe, modify options or view archives go to: > >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > >> Only members subscribed via the mailman list are allowed to post. > > > > -- > > Sending this from my phone, please excuse any typos! > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > > > > -- > brandon s allbery kf8nh > allbery.b at gmail.com > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. From migmit at gmail.com Sun Dec 9 18:41:20 2018 From: migmit at gmail.com (MigMit) Date: Sun, 9 Dec 2018 19:41:20 +0100 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: My guess — by finding a member that satisfies a predicate, if it's at all possible, and any member if the predicate is const False. It's actually pretty awesome. > On 9 Dec 2018, at 19:36, Brandon Allbery wrote: > > Naïvely, a set implemented as a predicate determining membership? > > On Sun, Dec 9, 2018 at 1:32 PM Siddharth Bhat wrote: > I don't understand, how does > > (a -> Bool) -> a > > model a set? > > Thanks > Siddharth > > On Sun, 9 Dec, 2018, 22:08 Olaf Klinke, wrote: > > Note that a concrete set "concretizes" anything it touches. Don't take > > unions of these sets, though, it'll just be a mess. > > > > > > Won't a union just be the same as intersection but using || instead of && ? > > > > > > -Jan-Willem Maessen > > Unions of predicates and concrete sets are easy, thanks to Set.member: > > union (Pred p) (Concrete s) = Pred (\k -> p k || member k s) > > What you can not do, of course, is enumerate and fold these sets. > There is a set type [1] which supports a litte bit more: > > Set a = Maybe ((a -> Bool) -> a) > > It has unions, intersections and a Monad instance and can represent infinite sets. If the base type has an Ord instance, the set can be enumerated. If the base type has an Eq instance, so has (Set a). Some functions usually implemented using Foldable are also possible, e.g. minimum and maximum. > Caveat: Performance can be poor, depending on how the function inside the set was defined. > > Cheers, > Olaf > > [1] http://hackage.haskell.org/package/infinite-search > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. > -- > Sending this from my phone, please excuse any typos! > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. > > > -- > brandon s allbery kf8nh > allbery.b at gmail.com > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. From david.feuer at gmail.com Sun Dec 9 18:47:44 2018 From: david.feuer at gmail.com (David Feuer) Date: Sun, 9 Dec 2018 13:47:44 -0500 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: That does seem to be what the source code says. The code only handles non-empty sets, but I *believe* the Maybe-wrapped version can handle intersections, albeit inefficiently. Can a version that looks like (a -> Bool) -> Maybe a work? On Sun, Dec 9, 2018, 1:41 PM MigMit My guess — by finding a member that satisfies a predicate, if it's at all > possible, and any member if the predicate is const False. It's actually > pretty awesome. > > > On 9 Dec 2018, at 19:36, Brandon Allbery wrote: > > > > Naïvely, a set implemented as a predicate determining membership? > > > > On Sun, Dec 9, 2018 at 1:32 PM Siddharth Bhat > wrote: > > I don't understand, how does > > > > (a -> Bool) -> a > > > > model a set? > > > > Thanks > > Siddharth > > > > On Sun, 9 Dec, 2018, 22:08 Olaf Klinke, wrote: > > > Note that a concrete set "concretizes" anything it touches. Don't take > > > unions of these sets, though, it'll just be a mess. > > > > > > > > > Won't a union just be the same as intersection but using || instead of > && ? > > > > > > > > > -Jan-Willem Maessen > > > > Unions of predicates and concrete sets are easy, thanks to Set.member: > > > > union (Pred p) (Concrete s) = Pred (\k -> p k || member k s) > > > > What you can not do, of course, is enumerate and fold these sets. > > There is a set type [1] which supports a litte bit more: > > > > Set a = Maybe ((a -> Bool) -> a) > > > > It has unions, intersections and a Monad instance and can represent > infinite sets. If the base type has an Ord instance, the set can be > enumerated. If the base type has an Eq instance, so has (Set a). Some > functions usually implemented using Foldable are also possible, e.g. > minimum and maximum. > > Caveat: Performance can be poor, depending on how the function inside > the set was defined. > > > > Cheers, > > Olaf > > > > [1] http://hackage.haskell.org/package/infinite-search > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > > -- > > Sending this from my phone, please excuse any typos! > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > > > > > > -- > > brandon s allbery kf8nh > > allbery.b at gmail.com > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From olf at aatal-apotheke.de Sun Dec 9 18:48:46 2018 From: olf at aatal-apotheke.de (Olaf Klinke) Date: Sun, 9 Dec 2018 19:48:46 +0100 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: > Am 09.12.2018 um 19:31 schrieb Siddharth Bhat : > > I don't understand, how does > > (a -> Bool) -> a > > model a set? MigMit was right. When I learned about this, I thought is was black magic. Suppose find :: (a -> Bool) -> a This function 'find' models a hypothetical non-empty set S. The specification is that for every predicate p :: a -> Bool that terminates on every element of S (this condition is important!), find p will be a member of S that satisfies p, if there is such a member, and any member of S otherwise. Since find is specified to always return a member of S, the set S is guaranteed to be non-empty. You can select some element from S by calling 'find' on (const True). For example, the singleton x is defined as the constant function \p -> x The doubleton {x,y} is defined as \p -> if p x then x else y Binary union is defined as union find find' = \p -> if p (find p) then find p else find' p Existential quantification over S: exists p = p (find p) Universal quantification over S: forall p = not (exists (not.p)) In order to represent the empty set as well, I stuck in the Maybe, so that Nothing represents the empty set and (Just find) represents a non-empty set. Olaf > > Thanks > Siddharth > > On Sun, 9 Dec, 2018, 22:08 Olaf Klinke, wrote: > > Note that a concrete set "concretizes" anything it touches. Don't take > > unions of these sets, though, it'll just be a mess. > > > > > > Won't a union just be the same as intersection but using || instead of && ? > > > > > > -Jan-Willem Maessen > > Unions of predicates and concrete sets are easy, thanks to Set.member: > > union (Pred p) (Concrete s) = Pred (\k -> p k || member k s) > > What you can not do, of course, is enumerate and fold these sets. > There is a set type [1] which supports a litte bit more: > > Set a = Maybe ((a -> Bool) -> a) > > It has unions, intersections and a Monad instance and can represent infinite sets. If the base type has an Ord instance, the set can be enumerated. If the base type has an Eq instance, so has (Set a). Some functions usually implemented using Foldable are also possible, e.g. minimum and maximum. > Caveat: Performance can be poor, depending on how the function inside the set was defined. > > Cheers, > Olaf > > [1] http://hackage.haskell.org/package/infinite-search > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. > -- > Sending this from my phone, please excuse any typos! From kc1956 at gmail.com Sun Dec 9 18:49:37 2018 From: kc1956 at gmail.com (KC) Date: Sun, 9 Dec 2018 10:49:37 -0800 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: Bloom Filters? If some false positives are OK -- Sent from an expensive device which will be obsolete in a few months Casey On Sat, Dec 8, 2018, 4:46 PM Jeffrey Brown The following expressions both cause GHCI to hang: > > > S.intersection (S.fromList [1,2]) (S.fromList [1..]) > fromList ^CInterrupted. > > S.intersection (S.fromList [1..]) (S.fromList [1,2]) > fromList ^CInterrupted. > > > > Is there a smarter way to take the intersection of sets when at least one > of them is small (but I don't know which one that is)? > > -- > Jeff Brown | Jeffrey Benjamin Brown > Website | Facebook > | LinkedIn > (spammy, so I often > miss messages here) | Github > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From olf at aatal-apotheke.de Sun Dec 9 19:30:47 2018 From: olf at aatal-apotheke.de (Olaf Klinke) Date: Sun, 9 Dec 2018 20:30:47 +0100 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: > Am 09.12.2018 um 19:47 schrieb David Feuer : > > That does seem to be what the source code says. The code only handles non-empty sets, but I *believe* the Maybe-wrapped version can handle intersections, albeit inefficiently. Can a version that looks like (a -> Bool) -> Maybe a work? I think so. The empty set is then represented by the function that returns Nothing even on (const True). Indeed, with Maybe on the outside the intersection function requires the Eq constraint on the base type: We have member :: Eq a => a -> ((a -> Bool) -> a) -> Bool member x find = x == (find (x==)) Then the intersection of find and find' can be implemented using \p -> find (\x -> p x && member x find') But I fail to see how having Maybe on the inside remedies this situation. Furthermore, on Eq types these sets are not so interesting, for the following reason. One can write a function Eq a => ((a -> Bool) -> a) -> [a] that enumerates the elements of the set. Because we have universal quantification, this list can not be infinite. Which makes sense, topologically: These so-called searchable sets are topologically compact, and the Eq constraint means the space is discrete. Compact subsets of a discrete space are finite. Olaf > > On Sun, Dec 9, 2018, 1:41 PM MigMit My guess — by finding a member that satisfies a predicate, if it's at all possible, and any member if the predicate is const False. It's actually pretty awesome. > > > On 9 Dec 2018, at 19:36, Brandon Allbery wrote: > > > > Naïvely, a set implemented as a predicate determining membership? > > > > On Sun, Dec 9, 2018 at 1:32 PM Siddharth Bhat wrote: > > I don't understand, how does > > > > (a -> Bool) -> a > > > > model a set? > > > > Thanks > > Siddharth > > > > On Sun, 9 Dec, 2018, 22:08 Olaf Klinke, wrote: > > > Note that a concrete set "concretizes" anything it touches. Don't take > > > unions of these sets, though, it'll just be a mess. > > > > > > > > > Won't a union just be the same as intersection but using || instead of && ? > > > > > > > > > -Jan-Willem Maessen > > > > Unions of predicates and concrete sets are easy, thanks to Set.member: > > > > union (Pred p) (Concrete s) = Pred (\k -> p k || member k s) > > > > What you can not do, of course, is enumerate and fold these sets. > > There is a set type [1] which supports a litte bit more: > > > > Set a = Maybe ((a -> Bool) -> a) > > > > It has unions, intersections and a Monad instance and can represent infinite sets. If the base type has an Ord instance, the set can be enumerated. If the base type has an Eq instance, so has (Set a). Some functions usually implemented using Foldable are also possible, e.g. minimum and maximum. > > Caveat: Performance can be poor, depending on how the function inside the set was defined. > > > > Cheers, > > Olaf > > > > [1] http://hackage.haskell.org/package/infinite-search > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > > -- > > Sending this from my phone, please excuse any typos! > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > > > > > > -- > > brandon s allbery kf8nh > > allbery.b at gmail.com > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. From david.feuer at gmail.com Sun Dec 9 20:54:45 2018 From: david.feuer at gmail.com (David Feuer) Date: Sun, 9 Dec 2018 15:54:45 -0500 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: On Sun, Dec 9, 2018, 2:30 PM Olaf Klinke > But I fail to see how having Maybe on the inside remedies this situation. > Furthermore, on Eq types these sets are not so interesting, for the > following reason. > With Maybe on the outside, you can't jump straight to defining the function; you must first determine whether the intersection is empty. To my mind, a more natural definition for (possibly empty) sets is data Set a = Set {find :: (a -> Maybe b) -> Maybe b} which really explains how this is a set. > > One can write a function > Eq a => ((a -> Bool) -> a) -> [a] > that enumerates the elements of the set. Because we have universal > quantification, this list can not be infinite. Which makes sense, > topologically: These so-called searchable sets are topologically compact, > and the Eq constraint means the space is discrete. Compact subsets of a > discrete space are finite. > I don't understand how that's finite and not just countable. -------------- next part -------------- An HTML attachment was scrubbed... URL: From david.feuer at gmail.com Sun Dec 9 20:56:12 2018 From: david.feuer at gmail.com (David Feuer) Date: Sun, 9 Dec 2018 15:56:12 -0500 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: On Sun, Dec 9, 2018, 3:54 PM David Feuer > I don't understand how that's finite and not just countable. > Ah, I guess because there's no way to look at all elements of an infinite set. D'oh. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From doug at cs.dartmouth.edu Mon Dec 10 03:19:45 2018 From: doug at cs.dartmouth.edu (Doug McIlroy) Date: Sun, 09 Dec 2018 22:19:45 -0500 Subject: [Haskell-cafe] Faster set intersections? Message-ID: <201812100319.wBA3Jjoa104955@tahoe.cs.Dartmouth.EDU> > The following expressions both cause GHCI to hang: > > S.intersection (S.fromList [1,2]) (S.fromList [1..]) > S.intersection (S.fromList [1..]) (S.fromList [1,2]) > > Is there a smarter way to take the intersection of sets when at least one > of them is small (but I don't know which one that is)? "Small" is not enough. If all you know is that the lists represent sets of integers, then S.intersection (S.fromList [-1,-2]) (S.fromList [1..]) must diverge. A sufficient condition for success in such examples is that the sets come from a well-ordered domain and are presented in order. Then it's easy to write a merge-like algorithm. Both sets can be infinite; every finite prefix of the intersection will eventually appear. (Note that the integers are not well-ordered, though the positive integers are.) Doug From siddu.druid at gmail.com Mon Dec 10 07:11:14 2018 From: siddu.druid at gmail.com (Siddharth Bhat) Date: Mon, 10 Dec 2018 12:41:14 +0530 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: <201812100319.wBA3Jjoa104955@tahoe.cs.Dartmouth.EDU> References: <201812100319.wBA3Jjoa104955@tahoe.cs.Dartmouth.EDU> Message-ID: According to this construction, enumeration will need some SAT enumeration like process, where you search with a new predicate barring all previous candidates? On Mon, 10 Dec, 2018, 08:50 Doug McIlroy, wrote: > > The following expressions both cause GHCI to hang: > > > > S.intersection (S.fromList [1,2]) (S.fromList [1..]) > > S.intersection (S.fromList [1..]) (S.fromList [1,2]) > > > > Is there a smarter way to take the intersection of sets when at least one > > of them is small (but I don't know which one that is)? > > "Small" is not enough. If all you know is that the lists > represent sets of integers, then > > S.intersection (S.fromList [-1,-2]) (S.fromList [1..]) > > must diverge. A sufficient condition for success in such examples > is that the sets come from a well-ordered domain and are presented > in order. Then it's easy to write a merge-like algorithm. > Both sets can be infinite; every finite prefix of the intersection > will eventually appear. > > (Note that the integers are not well-ordered, though the positive > integers are.) > > Doug > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -- Sending this from my phone, please excuse any typos! -------------- next part -------------- An HTML attachment was scrubbed... URL: From tomtau at connect.hku.hk Mon Dec 10 12:09:24 2018 From: tomtau at connect.hku.hk (Tomas Tauber) Date: Mon, 10 Dec 2018 20:09:24 +0800 Subject: [Haskell-cafe] Coercion Quantification-related Meetup Event in Hong Kong (December 13, 2018) Message-ID: <8384F57C-B8D0-4FFF-B41E-B6901ED64FF0@connect.hku.hk> FYI: https://www.meetup.com/HK-Functional-programming/events/256404067/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From siddu.druid at gmail.com Mon Dec 10 12:38:20 2018 From: siddu.druid at gmail.com (Siddharth Bhat) Date: Mon, 10 Dec 2018 18:08:20 +0530 Subject: [Haskell-cafe] References for topological arguments of programs? Message-ID: Hello, I was recently intrigued by this style of argument on haskell cafe: One can write a function Eq a => ((a -> Bool) -> a) -> [a] that enumerates the elements of the set. Because we have universal quantification, this list can not be infinite. Which makes sense, topologically: These so-called searchable sets are topologically compact, and the Eq constraint means the space is discrete. Compact subsets of a discrete space are finite. ------- I've seen arguments like these "in the wild" during Scott topology construction and in some other weird places (hyperfunctions), but I've never seen a systematic treatment of this. I'd love to have a reference (papers / textbook preferred) to self learn this stuff! Thanks Siddharth -- Sending this from my phone, please excuse any typos! -------------- next part -------------- An HTML attachment was scrubbed... URL: From till at iks.cs.ovgu.de Mon Dec 10 13:34:07 2018 From: till at iks.cs.ovgu.de (Till Mossakowski) Date: Mon, 10 Dec 2018 14:34:07 +0100 Subject: [Haskell-cafe] References for topological arguments of programs? In-Reply-To: References: Message-ID: <0ae23a09-627b-2b8a-258c-c71ac456b3ca@iks.cs.ovgu.de> Hi, Peter G. Hinman: Recursion-Theoretic Hierarchies might contain some related material. Best, Till Mossakowski Am 10.12.18 um 13:38 schrieb Siddharth Bhat: > Hello, > > I was recently intrigued by this style of argument on haskell cafe: > > > One can write a function > Eq a => ((a -> Bool) -> a) -> [a] > that enumerates the elements of the set. Because we have universal > quantification, this list can not be infinite. Which makes sense, > topologically: These so-called searchable sets are topologically > compact, and the Eq constraint means the space is discrete. Compact > subsets of a discrete space are finite. > ------- > > I've seen arguments like these "in the wild" during Scott topology > construction and in some other weird places (hyperfunctions), but I've > never seen a systematic treatment of this. > > > I'd love to have a reference (papers / textbook preferred) to self > learn this stuff! > > Thanks > Siddharth > -- > Sending this from my phone, please excuse any typos! > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattei at oca.eu Mon Dec 10 14:18:48 2018 From: mattei at oca.eu (Damien Mattei) Date: Mon, 10 Dec 2018 15:18:48 +0100 Subject: [Haskell-cafe] Fwd: [Haskell-beginners] monad and variable result In-Reply-To: <5C0E40B7.6010909@oca.eu> References: <5C0E40B7.6010909@oca.eu> Message-ID: <5C0E75C8.5000501@oca.eu> i'v got no solution from Haskell-beginners... perheaps is there some expert here? -------- Message transféré -------- Sujet : [Haskell-beginners] monad and variable result Date : Mon, 10 Dec 2018 11:32:23 +0100 De : Damien Mattei Répondre à : The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell Pour : The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell have some code that works but want to put it in a simple function without sucess: getBD :: Connection -> String -> Float getBD conn name = noBDfp where qry_head = "select `N° BD` from sidonie.Coordonnées where Nom = ?" :: Query bd_rows = do local_bd_rows <- query conn qry_head (Only (name::String)) return local_bd_rows i want the variable local_bd_rows accessible in the 'where' clause how can i do that? note the goal is to do the same thing of my main function that works : main :: IO () --main :: Int main = do conn <- connect defaultConnectInfo { connectHost = "moita", connectUser = "mattei", connectPassword = "******", connectDatabase = "sidonie" } -- we get all the Double Stars that have angular distance superior to a threshold of 1 second = 0.000278 degree rows <- query_ conn "SELECT Nom,distance FROM AngularDistance WHERE distance > 0.000278" forM_ rows $ \(name,distance) -> putStrLn $ Text.unpack name ++ " " ++ show (distance :: Double) -- we will get the Durchmusterung Number BD from Sidonie and WDS and compare them for a given name -- Warning: there could be multiple result in WDS for a given entry name (due to components) -- first we get the N°BD from sidonie let name = "A 20" -- let qry = "select `N° BD` from Coordonnées where Nom = " ++ name let qry_head = "select `N° BD` from sidonie.Coordonnées where Nom = ?" :: Query -- bd_rows <- query_ conn "select `N° BD` from sidonie.Coordonnées where Nom = 'A 20'" bd_rows <- query conn qry_head (Only (name::String)) putStrLn $ show bd_rows putStrLn $ show name let resLst = Prelude.map fromOnly bd_rows let noBDtxt = fromOnly (Prelude.head bd_rows) :: Text -- let noBD2 = _ (Prelude.head bd_rows) putStrLn $ show resLst putStrLn $ show noBDtxt forM_ bd_rows $ \(Only a) -> putStrLn $ Text.unpack a let noBDstr = Text.unpack noBDtxt :: String let noBDfp = read $ noBDstr :: Float putStr "noBDfp =" (putStrLn (show noBDfp)) close conn print "Exit." for now i have errors in the function: Prelude> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:47:28: error: • Ambiguous type variable ‘r0’ arising from a use of ‘query’ prevents the constraint ‘(QueryResults r0)’ from being solved. Relevant bindings include bd_rows :: IO [r0] (bound at UpdateSidonie.hs:46:9) Probable fix: use a type annotation to specify what ‘r0’ should be. These potential instances exist: instance Result a => QueryResults (Only a) -- Defined in ‘Database.MySQL.Simple.QueryResults’ instance (Result a, Result b) => QueryResults (a, b) -- Defined in ‘Database.MySQL.Simple.QueryResults’ instance (Result a, Result b, Result c) => QueryResults (a, b, c) -- Defined in ‘Database.MySQL.Simple.QueryResults’ ...plus 21 others (use -fprint-potential-instances to see them all) • In a stmt of a 'do' block: local_bd_rows <- query conn qry_head (Only (name :: String)) In the expression: do local_bd_rows <- query conn qry_head (Only (name :: String)) return local_bd_rows In an equation for ‘bd_rows’: bd_rows = do local_bd_rows <- query conn qry_head (Only (name :: String)) return local_bd_rows | 47 | local_bd_rows <- query conn qry_head (Only (name::String)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Failed, no modules loaded. -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From stuart at cs.uchicago.edu Mon Dec 10 14:43:43 2018 From: stuart at cs.uchicago.edu (Stuart A. Kurtz) Date: Mon, 10 Dec 2018 08:43:43 -0600 Subject: [Haskell-cafe] References for topological arguments of programs? In-Reply-To: References: Message-ID: <2459B766-1176-4A44-8DC3-42B30D9FD1E9@cs.uchicago.edu> I've not been following this, but (a -> Bool) -> a is essentially a choice function, which figured in Ernst Zermelo's proof of the well-ordering theorem. > On Dec 10, 2018, at 6:38 AM, Siddharth Bhat wrote: > > Hello, > > I was recently intrigued by this style of argument on haskell cafe: > > > One can write a function > Eq a => ((a -> Bool) -> a) -> [a] > that enumerates the elements of the set. Because we have universal quantification, this list can not be infinite. Which makes sense, topologically: These so-called searchable sets are topologically compact, and the Eq constraint means the space is discrete. Compact subsets of a discrete space are finite. > ------- > > I've seen arguments like these "in the wild" during Scott topology construction and in some other weird places (hyperfunctions), but I've never seen a systematic treatment of this. > > > I'd love to have a reference (papers / textbook preferred) to self learn this stuff! > > Thanks > Siddharth > -- > Sending this from my phone, please excuse any typos! > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. From seph at codex.scot Mon Dec 10 16:19:39 2018 From: seph at codex.scot (Seph Shewell Brockway) Date: Mon, 10 Dec 2018 16:19:39 +0000 Subject: [Haskell-cafe] Fwd: [Haskell-beginners] monad and variable result In-Reply-To: <5C0E75C8.5000501@oca.eu> References: <5C0E40B7.6010909@oca.eu> <5C0E75C8.5000501@oca.eu> Message-ID: <20181210161939.5qo4cqp4ddggqymm@leviathan> Hi Damien, On Mon, Dec 10, 2018 at 03:18:48PM +0100, Damien Mattei wrote: > have some code that works but want to put it in a simple function > without sucess: > > getBD :: Connection -> String -> Float > getBD conn name = noBDfp > where qry_head = "select `N° BD` from sidonie.Coordonnées where Nom = > ?" :: Query > bd_rows = do > local_bd_rows <- query conn qry_head (Only (name::String)) > return local_bd_rows > > > i want the variable local_bd_rows accessible in the 'where' clause > > how can i do that? You don’t seem to be using the function bd_rows anywhere in the main body of the definition. You would need to do something like getBD :: Connection -> String -> IO Float getBD = do rows <- bd_rows {- code that does something with the returned data -} Note the change to the type signature—querying the database is an IO action, and therefore takes place in the IO monad. Incidently, your use of do notation in the definition of bd_rows is unnecessary: do x <- doSomething return x is actually syntactic sugar for doSomething >>= \x -> return x which the monad laws state is equivalent to just doSomething. This is a common misapprehension among Haskell novices: the do notation is just a syntactic convenience, and it is perfectly possible to write monadic functions, including in the IO monad, without it. Hope at least some of this helps. Seph -- Seph Shewell Brockway, BSc MSc (Glas.) From mattei at oca.eu Mon Dec 10 17:06:30 2018 From: mattei at oca.eu (Damien Mattei) Date: Mon, 10 Dec 2018 18:06:30 +0100 Subject: [Haskell-cafe] Fwd: [Haskell-beginners] monad and variable result In-Reply-To: <20181210161939.5qo4cqp4ddggqymm@leviathan> References: <5C0E40B7.6010909@oca.eu> <5C0E75C8.5000501@oca.eu> <20181210161939.5qo4cqp4ddggqymm@leviathan> Message-ID: <5C0E9D16.9040500@oca.eu> for now i'm here: getBD :: Connection -> String -> Float getBD conn name = noBDfp where qry_head = "select `N° BD` from sidonie.Coordonnées where Nom = ?" :: Query -- bd_rows = -- do -- local_bd_rows <- query conn qry_head (Only (name::String)) -- return local_bd_rows bd_rows :: IO [Only Text] bd_rows = query conn qry_head (Only (name::String)) noBDtxt :: [Text] noBDtxt = fromOnly (Prelude.head bd_rows) noBDstr :: String noBDstr = Text.unpack noBDtxt :: String noBDfp = read $ noBDstr :: Float but it fails due to the IO : Prelude> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:53:42: error: • Couldn't match expected type ‘[Only [Text]]’ with actual type ‘IO [Only Text]’ • In the first argument of ‘Prelude.head’, namely ‘bd_rows’ In the first argument of ‘fromOnly’, namely ‘(Prelude.head bd_rows)’ In the expression: fromOnly (Prelude.head bd_rows) | 53 | noBDtxt = fromOnly (Prelude.head bd_rows) | ^^^^^^^ UpdateSidonie.hs:55:31: error: • Couldn't match expected type ‘Text’ with actual type ‘[Text]’ • In the first argument of ‘unpack’, namely ‘noBDtxt’ In the expression: unpack noBDtxt :: String In an equation for ‘noBDstr’: noBDstr = unpack noBDtxt :: String | 55 | noBDstr = Text.unpack noBDtxt :: String | ^^^^^^^ Failed, no modules loaded. Le 10/12/2018 17:19, Seph Shewell Brockway a écrit : > Hi Damien, > > On Mon, Dec 10, 2018 at 03:18:48PM +0100, Damien Mattei wrote: >> have some code that works but want to put it in a simple function >> without sucess: >> >> getBD :: Connection -> String -> Float >> getBD conn name = noBDfp >> where qry_head = "select `N° BD` from sidonie.Coordonnées where Nom = >> ?" :: Query >> bd_rows = do >> local_bd_rows <- query conn qry_head (Only (name::String)) >> return local_bd_rows >> >> >> i want the variable local_bd_rows accessible in the 'where' clause >> >> how can i do that? > > You don’t seem to be using the function bd_rows anywhere in the main > body of the definition. You would need to do something like > > getBD :: Connection -> String -> IO Float > getBD = do rows <- bd_rows > {- code that does something with the returned data -} > > Note the change to the type signature—querying the database is an IO > action, and therefore takes place in the IO monad. > > Incidently, your use of do notation in the definition of bd_rows is > unnecessary: > > do x <- doSomething > return x > > is actually syntactic sugar for > > doSomething >>= \x -> return x > > which the monad laws state is equivalent to just doSomething. This is a > common misapprehension among Haskell novices: the do notation is just a > syntactic convenience, and it is perfectly possible to write monadic > functions, including in the IO monad, without it. > > Hope at least some of this helps. > > Seph > -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From seph at codex.scot Mon Dec 10 18:56:36 2018 From: seph at codex.scot (Seph Shewell Brockway) Date: Mon, 10 Dec 2018 18:56:36 +0000 Subject: [Haskell-cafe] Fwd: [Haskell-beginners] monad and variable result In-Reply-To: <5C0E9D16.9040500@oca.eu> References: <5C0E40B7.6010909@oca.eu> <5C0E75C8.5000501@oca.eu> <20181210161939.5qo4cqp4ddggqymm@leviathan> <5C0E9D16.9040500@oca.eu> Message-ID: <20181210185636.ygmgdxgscbevwdk5@leviathan> On Mon, Dec 10, 2018 at 06:06:30PM +0100, Damien Mattei wrote: > for now i'm here: > > getBD :: Connection -> String -> Float > getBD conn name = noBDfp > where qry_head = "select `N° BD` from sidonie.Coordonnées where Nom = > ?" :: Query > -- bd_rows = > -- do > -- local_bd_rows <- query conn qry_head (Only (name::String)) > -- return local_bd_rows > bd_rows :: IO [Only Text] > bd_rows = query conn qry_head (Only (name::String)) > noBDtxt :: [Text] > noBDtxt = fromOnly (Prelude.head bd_rows) > noBDstr :: String > noBDstr = Text.unpack noBDtxt :: String > noBDfp = read $ noBDstr :: Float Okay, I think I understand how your code is structured now. The point to recognize is that bd_rows has type IO [Only Text], which is not the same type as [Only Text]. Prelude.head has the type [a] -> a, and so it can’t be used on bd_rows as-is. Fortunately, being a monad, IO has an instance of Functor for free, and we can go from head :: [Only Text] -> Only Text to fmap head :: IO [Only Text] -> IO (Only Text) which takes an IO operation returning [Only Text] and applies head to its result, giving an IO operation returning an Only Text. Can you see how the IO monad follows you through everything that uses its result? If you rewrite noBDtxt as noBDtxt :: IO [Text] noBDtxt = fmap (fromOnly . Prelude.head) bd_rows then noBDstr has to be rewritten in a similar way, and so on through to the final result, giving the main function a type of Connection -> String -> IO Float. A lot of the functions in your where clause can be amalgamated, for example by combining noBDtxt and noBDstr as noBDstr = fmap (Text.unpack . fromOnly . Prelude.head) Similarly, getBD takes the result of noBDfp and returns it unaltered, so why not just write getBD = fmap read noBDstr ? Let me know if you would like me to explain anything in this message in more detail. Regards, Seph -- Seph Shewell Brockway, BSc MSc (Glas.) From olf at aatal-apotheke.de Mon Dec 10 20:28:20 2018 From: olf at aatal-apotheke.de (Olaf Klinke) Date: Mon, 10 Dec 2018 21:28:20 +0100 Subject: [Haskell-cafe] References for topological arguments of programs? In-Reply-To: References: Message-ID: <03D6C87C-5278-4532-A524-4800C291AB7E@aatal-apotheke.de> I highly recommend the So-called "Barbados notes" [1] of Martín Escardó. It is a systematic development of synthetic topology, with program fragments in Haskell. It is to my knowledge the first appearance of the so-called searchable sets and contains many other gems. I myself have been working on "Haskell for mathematicians", which shall become an entry point to the language for those with a background stronger in mathematics than in other programming languages. It is planned to touch on many areas of mathematics, not only topology. If anyone would like to have a look at the current stage, I'd be happy to share the source. Olaf [1] Synthetic Topology: of Data Types and Classical Spaces https://www.sciencedirect.com/journal/electronic-notes-in-theoretical-computer-science/vol/87/ Pages 21-156, Open access [Disclaimer: Martín Escardó was one of my PhD supervisors.] > Am 10.12.2018 um 13:38 schrieb Siddharth Bhat : > > Hello, > > I was recently intrigued by this style of argument on haskell cafe: > > > One can write a function > Eq a => ((a -> Bool) -> a) -> [a] > that enumerates the elements of the set. Because we have universal quantification, this list can not be infinite. Which makes sense, topologically: These so-called searchable sets are topologically compact, and the Eq constraint means the space is discrete. Compact subsets of a discrete space are finite. > ------- > > I've seen arguments like these "in the wild" during Scott topology construction and in some other weird places (hyperfunctions), but I've never seen a systematic treatment of this. > > > I'd love to have a reference (papers / textbook preferred) to self learn this stuff! > > Thanks > Siddharth > -- > Sending this from my phone, please excuse any typos! From me at ara.io Mon Dec 10 20:32:14 2018 From: me at ara.io (Ara Adkins) Date: Mon, 10 Dec 2018 20:32:14 +0000 Subject: [Haskell-cafe] References for topological arguments of programs? In-Reply-To: <03D6C87C-5278-4532-A524-4800C291AB7E@aatal-apotheke.de> References: <03D6C87C-5278-4532-A524-4800C291AB7E@aatal-apotheke.de> Message-ID: <13C25548-0CA6-463D-96E1-D7D5FC27DCFA@ara.io> I’d love to take a read of the current stage of your book! _ara > On 10 Dec 2018, at 20:28, Olaf Klinke wrote: > > I highly recommend the So-called "Barbados notes" [1] of Martín Escardó. It is a systematic development of synthetic topology, with program fragments in Haskell. It is to my knowledge the first appearance of the so-called searchable sets and contains many other gems. > > I myself have been working on "Haskell for mathematicians", which shall become an entry point to the language for those with a background stronger in mathematics than in other programming languages. It is planned to touch on many areas of mathematics, not only topology. If anyone would like to have a look at the current stage, I'd be happy to share the source. > > Olaf > > [1] Synthetic Topology: of Data Types and Classical Spaces > https://www.sciencedirect.com/journal/electronic-notes-in-theoretical-computer-science/vol/87/ > Pages 21-156, Open access > > [Disclaimer: Martín Escardó was one of my PhD supervisors.] > >> Am 10.12.2018 um 13:38 schrieb Siddharth Bhat : >> >> Hello, >> >> I was recently intrigued by this style of argument on haskell cafe: >> >> >> One can write a function >> Eq a => ((a -> Bool) -> a) -> [a] >> that enumerates the elements of the set. Because we have universal quantification, this list can not be infinite. Which makes sense, topologically: These so-called searchable sets are topologically compact, and the Eq constraint means the space is discrete. Compact subsets of a discrete space are finite. >> ------- >> >> I've seen arguments like these "in the wild" during Scott topology construction and in some other weird places (hyperfunctions), but I've never seen a systematic treatment of this. >> >> >> I'd love to have a reference (papers / textbook preferred) to self learn this stuff! >> >> Thanks >> Siddharth >> -- >> Sending this from my phone, please excuse any typos! > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. From migmit at gmail.com Mon Dec 10 20:35:18 2018 From: migmit at gmail.com (MigMit) Date: Mon, 10 Dec 2018 21:35:18 +0100 Subject: [Haskell-cafe] References for topological arguments of programs? In-Reply-To: <13C25548-0CA6-463D-96E1-D7D5FC27DCFA@ara.io> References: <03D6C87C-5278-4532-A524-4800C291AB7E@aatal-apotheke.de> <13C25548-0CA6-463D-96E1-D7D5FC27DCFA@ara.io> Message-ID: <57F3E488-9428-49E7-BAB2-60A27AD7A177@gmail.com> Same here! Az iPademről küldve 2018. dec. 10. dátummal, 21:32 időpontban Ara Adkins írta: > I’d love to take a read of the current stage of your book! > > _ara > >> On 10 Dec 2018, at 20:28, Olaf Klinke wrote: >> >> I highly recommend the So-called "Barbados notes" [1] of Martín Escardó. It is a systematic development of synthetic topology, with program fragments in Haskell. It is to my knowledge the first appearance of the so-called searchable sets and contains many other gems. >> >> I myself have been working on "Haskell for mathematicians", which shall become an entry point to the language for those with a background stronger in mathematics than in other programming languages. It is planned to touch on many areas of mathematics, not only topology. If anyone would like to have a look at the current stage, I'd be happy to share the source. >> >> Olaf >> >> [1] Synthetic Topology: of Data Types and Classical Spaces >> https://www.sciencedirect.com/journal/electronic-notes-in-theoretical-computer-science/vol/87/ >> Pages 21-156, Open access >> >> [Disclaimer: Martín Escardó was one of my PhD supervisors.] >> >>> Am 10.12.2018 um 13:38 schrieb Siddharth Bhat : >>> >>> Hello, >>> >>> I was recently intrigued by this style of argument on haskell cafe: >>> >>> >>> One can write a function >>> Eq a => ((a -> Bool) -> a) -> [a] >>> that enumerates the elements of the set. Because we have universal quantification, this list can not be infinite. Which makes sense, topologically: These so-called searchable sets are topologically compact, and the Eq constraint means the space is discrete. Compact subsets of a discrete space are finite. >>> ------- >>> >>> I've seen arguments like these "in the wild" during Scott topology construction and in some other weird places (hyperfunctions), but I've never seen a systematic treatment of this. >>> >>> >>> I'd love to have a reference (papers / textbook preferred) to self learn this stuff! >>> >>> Thanks >>> Siddharth >>> -- >>> Sending this from my phone, please excuse any typos! >> >> _______________________________________________ >> Haskell-Cafe mailing list >> To (un)subscribe, modify options or view archives go to: >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> Only members subscribed via the mailman list are allowed to post. > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. From siddu.druid at gmail.com Mon Dec 10 20:56:23 2018 From: siddu.druid at gmail.com (Siddharth Bhat) Date: Tue, 11 Dec 2018 02:26:23 +0530 Subject: [Haskell-cafe] References for topological arguments of programs? In-Reply-To: <57F3E488-9428-49E7-BAB2-60A27AD7A177@gmail.com> References: <03D6C87C-5278-4532-A524-4800C291AB7E@aatal-apotheke.de> <13C25548-0CA6-463D-96E1-D7D5FC27DCFA@ara.io> <57F3E488-9428-49E7-BAB2-60A27AD7A177@gmail.com> Message-ID: Agreed, having access to the book would be fantastic. :) On Tue, 11 Dec, 2018, 02:05 MigMit, wrote: > Same here! > > Az iPademről küldve > > 2018. dec. 10. dátummal, 21:32 időpontban Ara Adkins írta: > > > I’d love to take a read of the current stage of your book! > > > > _ara > > > >> On 10 Dec 2018, at 20:28, Olaf Klinke wrote: > >> > >> I highly recommend the So-called "Barbados notes" [1] of Martín > Escardó. It is a systematic development of synthetic topology, with program > fragments in Haskell. It is to my knowledge the first appearance of the > so-called searchable sets and contains many other gems. > >> > >> I myself have been working on "Haskell for mathematicians", which shall > become an entry point to the language for those with a background stronger > in mathematics than in other programming languages. It is planned to touch > on many areas of mathematics, not only topology. If anyone would like to > have a look at the current stage, I'd be happy to share the source. > >> > >> Olaf > >> > >> [1] Synthetic Topology: of Data Types and Classical Spaces > >> > https://www.sciencedirect.com/journal/electronic-notes-in-theoretical-computer-science/vol/87/ > >> Pages 21-156, Open access > >> > >> [Disclaimer: Martín Escardó was one of my PhD supervisors.] > >> > >>> Am 10.12.2018 um 13:38 schrieb Siddharth Bhat : > >>> > >>> Hello, > >>> > >>> I was recently intrigued by this style of argument on haskell cafe: > >>> > >>> > >>> One can write a function > >>> Eq a => ((a -> Bool) -> a) -> [a] > >>> that enumerates the elements of the set. Because we have universal > quantification, this list can not be infinite. Which makes sense, > topologically: These so-called searchable sets are topologically compact, > and the Eq constraint means the space is discrete. Compact subsets of a > discrete space are finite. > >>> ------- > >>> > >>> I've seen arguments like these "in the wild" during Scott topology > construction and in some other weird places (hyperfunctions), but I've > never seen a systematic treatment of this. > >>> > >>> > >>> I'd love to have a reference (papers / textbook preferred) to self > learn this stuff! > >>> > >>> Thanks > >>> Siddharth > >>> -- > >>> Sending this from my phone, please excuse any typos! > >> > >> _______________________________________________ > >> Haskell-Cafe mailing list > >> To (un)subscribe, modify options or view archives go to: > >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > >> Only members subscribed via the mailman list are allowed to post. > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -- Sending this from my phone, please excuse any typos! -------------- next part -------------- An HTML attachment was scrubbed... URL: From olf at aatal-apotheke.de Mon Dec 10 21:05:03 2018 From: olf at aatal-apotheke.de (Olaf Klinke) Date: Mon, 10 Dec 2018 22:05:03 +0100 Subject: [Haskell-cafe] References for topological arguments of programs? In-Reply-To: References: <03D6C87C-5278-4532-A524-4800C291AB7E@aatal-apotheke.de> <13C25548-0CA6-463D-96E1-D7D5FC27DCFA@ara.io> <57F3E488-9428-49E7-BAB2-60A27AD7A177@gmail.com> Message-ID: <990E046A-A414-411D-83BC-6880E11A12EE@aatal-apotheke.de> I suggest to use Bhavik Mehta's page haskellformathematicians.wordpress.com if we can not find a more official place for it on haskell.org. At this point I'd like to thank Haskell Café member Sergiu Ivanov for inspiring me to start working on this. Does anyone know whether literate haskell can be used to generate html? Olaf > Am 10.12.2018 um 21:56 schrieb Siddharth Bhat : > > Agreed, having access to the book would be fantastic. :) > > On Tue, 11 Dec, 2018, 02:05 MigMit, wrote: > Same here! > > Az iPademről küldve > > 2018. dec. 10. dátummal, 21:32 időpontban Ara Adkins írta: > > > I’d love to take a read of the current stage of your book! > > > > _ara > > > >> On 10 Dec 2018, at 20:28, Olaf Klinke wrote: > >> > >> I highly recommend the So-called "Barbados notes" [1] of Martín Escardó. It is a systematic development of synthetic topology, with program fragments in Haskell. It is to my knowledge the first appearance of the so-called searchable sets and contains many other gems. > >> > >> I myself have been working on "Haskell for mathematicians", which shall become an entry point to the language for those with a background stronger in mathematics than in other programming languages. It is planned to touch on many areas of mathematics, not only topology. If anyone would like to have a look at the current stage, I'd be happy to share the source. > >> > >> Olaf > >> > >> [1] Synthetic Topology: of Data Types and Classical Spaces > >> https://www.sciencedirect.com/journal/electronic-notes-in-theoretical-computer-science/vol/87/ > >> Pages 21-156, Open access > >> > >> [Disclaimer: Martín Escardó was one of my PhD supervisors.] > >> > >>> Am 10.12.2018 um 13:38 schrieb Siddharth Bhat : > >>> > >>> Hello, > >>> > >>> I was recently intrigued by this style of argument on haskell cafe: > >>> > >>> > >>> One can write a function > >>> Eq a => ((a -> Bool) -> a) -> [a] > >>> that enumerates the elements of the set. Because we have universal quantification, this list can not be infinite. Which makes sense, topologically: These so-called searchable sets are topologically compact, and the Eq constraint means the space is discrete. Compact subsets of a discrete space are finite. > >>> ------- > >>> > >>> I've seen arguments like these "in the wild" during Scott topology construction and in some other weird places (hyperfunctions), but I've never seen a systematic treatment of this. > >>> > >>> > >>> I'd love to have a reference (papers / textbook preferred) to self learn this stuff! > >>> > >>> Thanks > >>> Siddharth > >>> -- > >>> Sending this from my phone, please excuse any typos! > >> > >> _______________________________________________ > >> Haskell-Cafe mailing list > >> To (un)subscribe, modify options or view archives go to: > >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > >> Only members subscribed via the mailman list are allowed to post. > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. > -- > Sending this from my phone, please excuse any typos! From me at ara.io Mon Dec 10 21:06:10 2018 From: me at ara.io (Ara Adkins) Date: Mon, 10 Dec 2018 21:06:10 +0000 Subject: [Haskell-cafe] References for topological arguments of programs? In-Reply-To: <990E046A-A414-411D-83BC-6880E11A12EE@aatal-apotheke.de> References: <03D6C87C-5278-4532-A524-4800C291AB7E@aatal-apotheke.de> <13C25548-0CA6-463D-96E1-D7D5FC27DCFA@ara.io> <57F3E488-9428-49E7-BAB2-60A27AD7A177@gmail.com> <990E046A-A414-411D-83BC-6880E11A12EE@aatal-apotheke.de> Message-ID: <52AC1FDC-D06A-4327-9D51-17BFBCAB669A@ara.io> Thanks so much Olaf! I’m looking forward to giving this a read on my plane ride tomorrow! _ara > On 10 Dec 2018, at 21:05, Olaf Klinke wrote: > > I suggest to use Bhavik Mehta's page haskellformathematicians.wordpress.com if we can not find a more official place for it on haskell.org. At this point I'd like to thank Haskell Café member Sergiu Ivanov for inspiring me to start working on this. > > Does anyone know whether literate haskell can be used to generate html? > > Olaf > >> Am 10.12.2018 um 21:56 schrieb Siddharth Bhat : >> >> Agreed, having access to the book would be fantastic. :) >> >> On Tue, 11 Dec, 2018, 02:05 MigMit, wrote: >> Same here! >> >> Az iPademről küldve >> >> 2018. dec. 10. dátummal, 21:32 időpontban Ara Adkins írta: >> >>> I’d love to take a read of the current stage of your book! >>> >>> _ara >>> >>>> On 10 Dec 2018, at 20:28, Olaf Klinke wrote: >>>> >>>> I highly recommend the So-called "Barbados notes" [1] of Martín Escardó. It is a systematic development of synthetic topology, with program fragments in Haskell. It is to my knowledge the first appearance of the so-called searchable sets and contains many other gems. >>>> >>>> I myself have been working on "Haskell for mathematicians", which shall become an entry point to the language for those with a background stronger in mathematics than in other programming languages. It is planned to touch on many areas of mathematics, not only topology. If anyone would like to have a look at the current stage, I'd be happy to share the source. >>>> >>>> Olaf >>>> >>>> [1] Synthetic Topology: of Data Types and Classical Spaces >>>> https://www.sciencedirect.com/journal/electronic-notes-in-theoretical-computer-science/vol/87/ >>>> Pages 21-156, Open access >>>> >>>> [Disclaimer: Martín Escardó was one of my PhD supervisors.] >>>> >>>>> Am 10.12.2018 um 13:38 schrieb Siddharth Bhat : >>>>> >>>>> Hello, >>>>> >>>>> I was recently intrigued by this style of argument on haskell cafe: >>>>> >>>>> >>>>> One can write a function >>>>> Eq a => ((a -> Bool) -> a) -> [a] >>>>> that enumerates the elements of the set. Because we have universal quantification, this list can not be infinite. Which makes sense, topologically: These so-called searchable sets are topologically compact, and the Eq constraint means the space is discrete. Compact subsets of a discrete space are finite. >>>>> ------- >>>>> >>>>> I've seen arguments like these "in the wild" during Scott topology construction and in some other weird places (hyperfunctions), but I've never seen a systematic treatment of this. >>>>> >>>>> >>>>> I'd love to have a reference (papers / textbook preferred) to self learn this stuff! >>>>> >>>>> Thanks >>>>> Siddharth >>>>> -- >>>>> Sending this from my phone, please excuse any typos! >>>> >>>> _______________________________________________ >>>> Haskell-Cafe mailing list >>>> To (un)subscribe, modify options or view archives go to: >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >>>> Only members subscribed via the mailman list are allowed to post. >>> _______________________________________________ >>> Haskell-Cafe mailing list >>> To (un)subscribe, modify options or view archives go to: >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >>> Only members subscribed via the mailman list are allowed to post. >> _______________________________________________ >> Haskell-Cafe mailing list >> To (un)subscribe, modify options or view archives go to: >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> Only members subscribed via the mailman list are allowed to post. >> -- >> Sending this from my phone, please excuse any typos! > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. From bhavikmehta8 at gmail.com Mon Dec 10 21:32:25 2018 From: bhavikmehta8 at gmail.com (Bhavik Mehta) Date: Mon, 10 Dec 2018 21:32:25 +0000 Subject: [Haskell-cafe] References for topological arguments of programs? In-Reply-To: <990E046A-A414-411D-83BC-6880E11A12EE@aatal-apotheke.de> References: <03D6C87C-5278-4532-A524-4800C291AB7E@aatal-apotheke.de> <13C25548-0CA6-463D-96E1-D7D5FC27DCFA@ara.io> <57F3E488-9428-49E7-BAB2-60A27AD7A177@gmail.com> <990E046A-A414-411D-83BC-6880E11A12EE@aatal-apotheke.de> Message-ID: I'm happy to do this, I'll aim to put it up over the next few days! Bhavik Mehta On Mon, 10 Dec 2018 at 21:05, Olaf Klinke wrote: > I suggest to use Bhavik Mehta's page > haskellformathematicians.wordpress.com if we can not find a more official > place for it on haskell.org. At this point I'd like to thank Haskell Café > member Sergiu Ivanov for inspiring me to start working on this. > > Does anyone know whether literate haskell can be used to generate html? > > Olaf > > > Am 10.12.2018 um 21:56 schrieb Siddharth Bhat : > > > > Agreed, having access to the book would be fantastic. :) > > > > On Tue, 11 Dec, 2018, 02:05 MigMit, wrote: > > Same here! > > > > Az iPademről küldve > > > > 2018. dec. 10. dátummal, 21:32 időpontban Ara Adkins írta: > > > > > I’d love to take a read of the current stage of your book! > > > > > > _ara > > > > > >> On 10 Dec 2018, at 20:28, Olaf Klinke wrote: > > >> > > >> I highly recommend the So-called "Barbados notes" [1] of Martín > Escardó. It is a systematic development of synthetic topology, with program > fragments in Haskell. It is to my knowledge the first appearance of the > so-called searchable sets and contains many other gems. > > >> > > >> I myself have been working on "Haskell for mathematicians", which > shall become an entry point to the language for those with a background > stronger in mathematics than in other programming languages. It is planned > to touch on many areas of mathematics, not only topology. If anyone would > like to have a look at the current stage, I'd be happy to share the source. > > >> > > >> Olaf > > >> > > >> [1] Synthetic Topology: of Data Types and Classical Spaces > > >> > https://www.sciencedirect.com/journal/electronic-notes-in-theoretical-computer-science/vol/87/ > > >> Pages 21-156, Open access > > >> > > >> [Disclaimer: Martín Escardó was one of my PhD supervisors.] > > >> > > >>> Am 10.12.2018 um 13:38 schrieb Siddharth Bhat >: > > >>> > > >>> Hello, > > >>> > > >>> I was recently intrigued by this style of argument on haskell cafe: > > >>> > > >>> > > >>> One can write a function > > >>> Eq a => ((a -> Bool) -> a) -> [a] > > >>> that enumerates the elements of the set. Because we have universal > quantification, this list can not be infinite. Which makes sense, > topologically: These so-called searchable sets are topologically compact, > and the Eq constraint means the space is discrete. Compact subsets of a > discrete space are finite. > > >>> ------- > > >>> > > >>> I've seen arguments like these "in the wild" during Scott topology > construction and in some other weird places (hyperfunctions), but I've > never seen a systematic treatment of this. > > >>> > > >>> > > >>> I'd love to have a reference (papers / textbook preferred) to self > learn this stuff! > > >>> > > >>> Thanks > > >>> Siddharth > > >>> -- > > >>> Sending this from my phone, please excuse any typos! > > >> > > >> _______________________________________________ > > >> Haskell-Cafe mailing list > > >> To (un)subscribe, modify options or view archives go to: > > >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > >> Only members subscribed via the mailman list are allowed to post. > > > _______________________________________________ > > > Haskell-Cafe mailing list > > > To (un)subscribe, modify options or view archives go to: > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > > Only members subscribed via the mailman list are allowed to post. > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > > -- > > Sending this from my phone, please excuse any typos! > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bandali at gnu.org Mon Dec 10 21:33:09 2018 From: bandali at gnu.org (Amin Bandali) Date: Mon, 10 Dec 2018 16:33:09 -0500 Subject: [Haskell-cafe] References for topological arguments of programs? In-Reply-To: <990E046A-A414-411D-83BC-6880E11A12EE@aatal-apotheke.de> (Olaf Klinke's message of "Mon, 10 Dec 2018 22:05:03 +0100") References: <03D6C87C-5278-4532-A524-4800C291AB7E@aatal-apotheke.de> <13C25548-0CA6-463D-96E1-D7D5FC27DCFA@ara.io> <57F3E488-9428-49E7-BAB2-60A27AD7A177@gmail.com> <990E046A-A414-411D-83BC-6880E11A12EE@aatal-apotheke.de> Message-ID: <877egh5ap6.fsf@aminb.org> > Does anyone know whether literate haskell can be used to generate html? You can use Pandoc¹. Or alternatively, first use lhs2tex² to get LaTeX, and then use Pandoc or one of the tools listed here³ to convert LaTeX to HTML. I haven’t tried either of the approaches, so it would be nice if someone could speak on how they compare in terms of the quality of the final document. HTH. Footnotes: ¹ https://pandoc.org/MANUAL.html#literate-haskell-support ² https://hackage.haskell.org/package/lhs2tex ³ https://texfaq.org/FAQ-LaTeX2HTML From ryan.reich at gmail.com Mon Dec 10 21:53:07 2018 From: ryan.reich at gmail.com (Ryan Reich) Date: Mon, 10 Dec 2018 13:53:07 -0800 Subject: [Haskell-cafe] References for topological arguments of programs? In-Reply-To: <03D6C87C-5278-4532-A524-4800C291AB7E@aatal-apotheke.de> References: <03D6C87C-5278-4532-A524-4800C291AB7E@aatal-apotheke.de> Message-ID: Hi Olaf, I think I'd be interested in seeing your work-in-progress. Ryan Reich On Mon, Dec 10, 2018 at 12:29 PM Olaf Klinke wrote: > I highly recommend the So-called "Barbados notes" [1] of Martín Escardó. > It is a systematic development of synthetic topology, with program > fragments in Haskell. It is to my knowledge the first appearance of the > so-called searchable sets and contains many other gems. > > I myself have been working on "Haskell for mathematicians", which shall > become an entry point to the language for those with a background stronger > in mathematics than in other programming languages. It is planned to touch > on many areas of mathematics, not only topology. If anyone would like to > have a look at the current stage, I'd be happy to share the source. > > Olaf > > [1] Synthetic Topology: of Data Types and Classical Spaces > > https://www.sciencedirect.com/journal/electronic-notes-in-theoretical-computer-science/vol/87/ > Pages 21-156, Open access > > [Disclaimer: Martín Escardó was one of my PhD supervisors.] > > > Am 10.12.2018 um 13:38 schrieb Siddharth Bhat : > > > > Hello, > > > > I was recently intrigued by this style of argument on haskell cafe: > > > > > > One can write a function > > Eq a => ((a -> Bool) -> a) -> [a] > > that enumerates the elements of the set. Because we have universal > quantification, this list can not be infinite. Which makes sense, > topologically: These so-called searchable sets are topologically compact, > and the Eq constraint means the space is discrete. Compact subsets of a > discrete space are finite. > > ------- > > > > I've seen arguments like these "in the wild" during Scott topology > construction and in some other weird places (hyperfunctions), but I've > never seen a systematic treatment of this. > > > > > > I'd love to have a reference (papers / textbook preferred) to self learn > this stuff! > > > > Thanks > > Siddharth > > -- > > Sending this from my phone, please excuse any typos! > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben.franksen at online.de Mon Dec 10 23:48:57 2018 From: ben.franksen at online.de (Ben Franksen) Date: Tue, 11 Dec 2018 00:48:57 +0100 Subject: [Haskell-cafe] role constraints Message-ID: I have a question about roles for type variables. I have a number of data types that more or less represent partial bijections. They take two type parameters that represent domain and range. The phantom type parameters are extremely useful: code that shuffles these things around will fail to type check if domains and ranges don't match up exactly. However, there are some situations where I know more about the semantics than the type checker and need to be able to coerce the phantom parameters. No problem, that's what coerce is for... Except, most of the code is polymorphic over the data type, requiring only a few class constraints. And this polymorphism forces the type checker to assume representational roles for the type parameters. Which means I can't use coerce. Instead I have to use unsafeCoerce which I would like to avoid. Is there a way to express, as a constraint, that a certain parameter has a phantom role? What I want to say is: you are only allowed to instantiate the type variable 'a :: * -> * -> *' with data type 'A' if 'x' and 'y' in 'A x y' have both role phantom. And what I get is that I can call coerce to modify the parameters 'x' and 'y'. From clintonmead at gmail.com Mon Dec 10 23:50:15 2018 From: clintonmead at gmail.com (Clinton Mead) Date: Tue, 11 Dec 2018 10:50:15 +1100 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: > > > One can write a function > Eq a => ((a -> Bool) -> a) -> [a] > that enumerates the elements of the set. Because we have universal > quantification, this list can not be infinite. Which makes sense, > topologically: These so-called searchable sets are topologically compact, > and the Eq constraint means the space is discrete. Compact subsets of a > discrete space are finite. > > Olaf > > Olaf (or anyone else), can you help me out here and write this function, with some example inputs and outputs? -------------- next part -------------- An HTML attachment was scrubbed... URL: From capn.freako at gmail.com Mon Dec 10 23:57:40 2018 From: capn.freako at gmail.com (David Banas) Date: Mon, 10 Dec 2018 15:57:40 -0800 Subject: [Haskell-cafe] Literate Haskell to HTML? In-Reply-To: References: Message-ID: Hi Olaf, Yes, I routinely generate HTML from *.lhs files, using Pandoc. -db > On Dec 10, 2018, at 3:03 PM, haskell-cafe-request at haskell.org wrote: > > Does anyone know whether literate haskell can be used to generate html? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rae at cs.brynmawr.edu Tue Dec 11 02:04:40 2018 From: rae at cs.brynmawr.edu (Richard Eisenberg) Date: Mon, 10 Dec 2018 21:04:40 -0500 Subject: [Haskell-cafe] role constraints In-Reply-To: References: Message-ID: <760C0D7F-A33D-4548-866D-721976F902FF@cs.brynmawr.edu> You can use quantified constraints to get some approximation of the behavior you want. For example: > foo :: forall a. (forall x y. Coercible (a x) (a y)) => ... a ... This means, effectively, that a's parameter's role must be phantom. I've seen some bug reports fly by that talk about situations like these and how the solver sometimes isn't the best in these scenarios, but this approach just might work for you. Richard > On Dec 10, 2018, at 6:48 PM, Ben Franksen wrote: > > I have a question about roles for type variables. I have a number of > data types that more or less represent partial bijections. They take two > type parameters that represent domain and range. The phantom type > parameters are extremely useful: code that shuffles these things around > will fail to type check if domains and ranges don't match up exactly. > However, there are some situations where I know more about the semantics > than the type checker and need to be able to coerce the phantom > parameters. No problem, that's what coerce is for... > > Except, most of the code is polymorphic over the data type, requiring > only a few class constraints. And this polymorphism forces the type > checker to assume representational roles for the type parameters. Which > means I can't use coerce. Instead I have to use unsafeCoerce which I > would like to avoid. > > Is there a way to express, as a constraint, that a certain parameter has > a phantom role? What I want to say is: you are only allowed to > instantiate the type variable 'a :: * -> * -> *' with data type 'A' if > 'x' and 'y' in 'A x y' have both role phantom. And what I get is that I > can call coerce to modify the parameters 'x' and 'y'. > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. From dsf at seereason.com Tue Dec 11 04:16:45 2018 From: dsf at seereason.com (David Fox) Date: Mon, 10 Dec 2018 20:16:45 -0800 Subject: [Haskell-cafe] version sorting? In-Reply-To: References: <20181208103815.2rilpreha2uamnlx@x60s.casa> <20181208133125.GD4966@teal.hq.k1024.org> <20181208140820.4ifb64ttgvxwlwni@x60s.casa> <20181208140943.GB28859@teal.hq.k1024.org> <20181208143335.ufx263kkynwa6k6i@x60s.casa> Message-ID: There is an implementation of the debian version sorting algorithm here: http://hackage.haskell.org/package/debian-3.93.2/docs/Debian-Version.html On Sat, Dec 8, 2018 at 11:40 AM Javran Cheng wrote: > Thanks for the suggestion! natural-sort looks like what I want - I've just > taken a quick look and the algorithm is almost the same if I'm not mistaken. > > also thanks MarLinn - it's just that as I wrote I realized I've been > implemented "tr" over and over again so there might be a common name for > it. I do recognize there's a (***) out there > and hoogling (a, [a]) -> [a] doesn't yield any function of interest., > didn't bother to go any further to see the rest of it is just a curried (:). > I'd still prefer "tr" though as for me if you think it as a rewrite rule, > it's more readable than having a chain of function composition. > > Cheers! > > On Sat, Dec 8, 2018 at 6:34 AM Francesco Ariis wrote: > >> On Sat, Dec 08, 2018 at 03:09:43PM +0100, Iustin Pop wrote: >> > Apologies - given the ".12", I implicitly translated ".2" as ".20". Just >> > a slow day :) >> >> No worries, I have bitten by "0.x/0.x0" more times than I am willing to >> admit :P >> -F >> _______________________________________________ >> Haskell-Cafe mailing list >> To (un)subscribe, modify options or view archives go to: >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> Only members subscribed via the mailman list are allowed to post. > > > > -- > Javran (Fang) Cheng > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From isaace71295 at gmail.com Tue Dec 11 06:55:07 2018 From: isaace71295 at gmail.com (Isaac Elliott) Date: Tue, 11 Dec 2018 16:55:07 +1000 Subject: [Haskell-cafe] Is unfoldr too strict? Message-ID: I was reading this article https://wiki.haskell.org/Correctness_of_short_cut_fusion on the Haskell wiki. It presents an example (2.1.2) where destroy/unfoldr fusion behaves oddly. If I use a lazier definition of unfoldr, then this problem goes away: unfoldr :: (b -> Maybe (a, b)) -> b -> [a] > unfoldr f b = > case f b of > Nothing -> [] > Just z -> fst z : unfoldr f (snd z) Does this mean unfoldr is 'too strict'? Or is there a good reason for not writing it this way (performance, perhaps?) -------------- next part -------------- An HTML attachment was scrubbed... URL: From vanessa.mchale at iohk.io Tue Dec 11 09:43:37 2018 From: vanessa.mchale at iohk.io (Vanessa McHale) Date: Tue, 11 Dec 2018 03:43:37 -0600 Subject: [Haskell-cafe] References for topological arguments of programs? In-Reply-To: <03D6C87C-5278-4532-A524-4800C291AB7E@aatal-apotheke.de> References: <03D6C87C-5278-4532-A524-4800C291AB7E@aatal-apotheke.de> Message-ID: I'd be quite interested in such a book/monograph - less as an introduction to the language and more as a way of seeing the higher mathematics one can use in Haskell/functional programming. On 12/10/18 2:28 PM, Olaf Klinke wrote: > I highly recommend the So-called "Barbados notes" [1] of Martín Escardó. It is a systematic development of synthetic topology, with program fragments in Haskell. It is to my knowledge the first appearance of the so-called searchable sets and contains many other gems. > > I myself have been working on "Haskell for mathematicians", which shall become an entry point to the language for those with a background stronger in mathematics than in other programming languages. It is planned to touch on many areas of mathematics, not only topology. If anyone would like to have a look at the current stage, I'd be happy to share the source. > > Olaf > > [1] Synthetic Topology: of Data Types and Classical Spaces > https://www.sciencedirect.com/journal/electronic-notes-in-theoretical-computer-science/vol/87/ > Pages 21-156, Open access > > [Disclaimer: Martín Escardó was one of my PhD supervisors.] > >> Am 10.12.2018 um 13:38 schrieb Siddharth Bhat : >> >> Hello, >> >> I was recently intrigued by this style of argument on haskell cafe: >> >> >> One can write a function >> Eq a => ((a -> Bool) -> a) -> [a] >> that enumerates the elements of the set. Because we have universal quantification, this list can not be infinite. Which makes sense, topologically: These so-called searchable sets are topologically compact, and the Eq constraint means the space is discrete. Compact subsets of a discrete space are finite. >> ------- >> >> I've seen arguments like these "in the wild" during Scott topology construction and in some other weird places (hyperfunctions), but I've never seen a systematic treatment of this. >> >> >> I'd love to have a reference (papers / textbook preferred) to self learn this stuff! >> >> Thanks >> Siddharth >> -- >> Sending this from my phone, please excuse any typos! > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From vanessa.mchale at iohk.io Tue Dec 11 09:50:16 2018 From: vanessa.mchale at iohk.io (Vanessa McHale) Date: Tue, 11 Dec 2018 03:50:16 -0600 Subject: [Haskell-cafe] Is unfoldr too strict? In-Reply-To: References: Message-ID: <47c28934-c4c3-f251-cffe-c70bc3eaabb8@iohk.io> I think the "official" version could be implemented with a lazy pattern match and it'd be the same as yours, no? Cheers, Vanessa On 12/11/18 12:55 AM, Isaac Elliott wrote: > I was reading this > article https://wiki.haskell.org/Correctness_of_short_cut_fusion on > the Haskell wiki. It presents an example (2.1.2) where destroy/unfoldr > fusion behaves oddly. If I use a lazier definition of unfoldr, then > this problem goes away: > > unfoldr :: (b -> Maybe (a, b)) -> b -> [a] > unfoldr f b = >   case f b of >     Nothing -> [] >     Just z -> fst z : unfoldr f (snd z) > > > Does this mean unfoldr is 'too strict'? Or is there a good reason for > not writing it this way (performance, perhaps?)  > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From isaace71295 at gmail.com Tue Dec 11 10:15:06 2018 From: isaace71295 at gmail.com (Isaac Elliott) Date: Tue, 11 Dec 2018 20:15:06 +1000 Subject: [Haskell-cafe] Is unfoldr too strict? In-Reply-To: <47c28934-c4c3-f251-cffe-c70bc3eaabb8@iohk.io> References: <47c28934-c4c3-f251-cffe-c70bc3eaabb8@iohk.io> Message-ID: Yep, a lazy pattern match gets you the same benefit. On Tue, 11 Dec. 2018, 7:50 pm Vanessa McHale, wrote: > I think the "official" version could be implemented with a lazy pattern > match and it'd be the same as yours, no? > > Cheers, > Vanessa > On 12/11/18 12:55 AM, Isaac Elliott wrote: > > I was reading this article > https://wiki.haskell.org/Correctness_of_short_cut_fusion on the Haskell > wiki. It presents an example (2.1.2) where destroy/unfoldr fusion behaves > oddly. If I use a lazier definition of unfoldr, then this problem goes away: > > unfoldr :: (b -> Maybe (a, b)) -> b -> [a] >> unfoldr f b = >> case f b of >> Nothing -> [] >> Just z -> fst z : unfoldr f (snd z) > > > Does this mean unfoldr is 'too strict'? Or is there a good reason for not > writing it this way (performance, perhaps?) > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to:http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattei at oca.eu Tue Dec 11 15:54:24 2018 From: mattei at oca.eu (Damien Mattei) Date: Tue, 11 Dec 2018 16:54:24 +0100 Subject: [Haskell-cafe] Fwd: [Haskell-beginners] monad and variable result In-Reply-To: <20181210185636.ygmgdxgscbevwdk5@leviathan> References: <5C0E40B7.6010909@oca.eu> <5C0E75C8.5000501@oca.eu> <20181210161939.5qo4cqp4ddggqymm@leviathan> <5C0E9D16.9040500@oca.eu> <20181210185636.ygmgdxgscbevwdk5@leviathan> Message-ID: <5C0FDDB0.3040207@oca.eu> Thank you Seph, with your help and reading some pages i can get to this: getBD :: Connection -> String -> IO Float getBD conn name = noBDfp where qry_head = "select `N° BD` from sidonie.Coordonnées where Nom = ?" :: Query bd_rows :: IO [Only Text] bd_rows = query conn qry_head (Only (name::String)) -- noBDtxt :: [Text] -- noBDtxt = fromOnly (Prelude.head bd_rows) -- noBDtxt :: IO [Text] noBDtxt :: IO Text noBDtxt = fmap (fromOnly . Prelude.head) bd_rows -- noBDstr :: String -- noBDstr = Text.unpack noBDtxt noBDstr :: IO String noBDstr = fmap Text.unpack noBDtxt -- noBDfp = read $ noBDstr :: Float noBDfp = fmap read noBDstr :: IO Float which compile but the question rest entire :how can i get the loat number from all this? i have a Main that looks like this: main :: IO () --main :: Int main = do conn <- connect defaultConnectInfo { connectHost = "moita", connectUser = "mattei", connectPassword = "sidonie2", connectDatabase = "sidonie" } -- first we get the N°BD from sidonie let name = "A 20" let noBD_IO = getBD conn name -- putStrLn $ show $ read $ Text.unpack noBD_IO close conn print "Exit." how can i get the float number from noBD_IO ? Regards, Damien Le 10/12/2018 19:56, Seph Shewell Brockway a écrit : > On Mon, Dec 10, 2018 at 06:06:30PM +0100, Damien Mattei wrote: >> for now i'm here: >> >> getBD :: Connection -> String -> Float >> getBD conn name = noBDfp >> where qry_head = "select `N° BD` from sidonie.Coordonnées where Nom = >> ?" :: Query >> -- bd_rows = >> -- do >> -- local_bd_rows <- query conn qry_head (Only (name::String)) >> -- return local_bd_rows >> bd_rows :: IO [Only Text] >> bd_rows = query conn qry_head (Only (name::String)) >> noBDtxt :: [Text] >> noBDtxt = fromOnly (Prelude.head bd_rows) >> noBDstr :: String >> noBDstr = Text.unpack noBDtxt :: String >> noBDfp = read $ noBDstr :: Float > > Okay, I think I understand how your code is structured now. The point to > recognize is that bd_rows has type IO [Only Text], which is not the same > type as [Only Text]. Prelude.head has the type [a] -> a, and so it can’t > be used on bd_rows as-is. Fortunately, being a monad, IO has an instance > of Functor for free, and we can go from > > head :: [Only Text] -> Only Text > > to > > fmap head :: IO [Only Text] -> IO (Only Text) > > which takes an IO operation returning [Only Text] and applies head to > its result, giving an IO operation returning an Only Text. > > Can you see how the IO monad follows you through everything that uses > its result? If you rewrite noBDtxt as > > noBDtxt :: IO [Text] > noBDtxt = fmap (fromOnly . Prelude.head) bd_rows > > then noBDstr has to be rewritten in a similar way, and so on through to > the final result, giving the main function a type of > Connection -> String -> IO Float. > > A lot of the functions in your where clause can be amalgamated, for > example by combining noBDtxt and noBDstr as > > noBDstr = fmap (Text.unpack . fromOnly . Prelude.head) > > Similarly, getBD takes the result of noBDfp and returns it unaltered, so > why not just write > > getBD = fmap read noBDstr > > ? > > Let me know if you would like me to explain anything in this message in more > detail. > > Regards, > > Seph > -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From olf at aatal-apotheke.de Tue Dec 11 18:58:08 2018 From: olf at aatal-apotheke.de (Olaf Klinke) Date: Tue, 11 Dec 2018 19:58:08 +0100 Subject: [Haskell-cafe] Faster set intersections? In-Reply-To: References: Message-ID: <93715A97-5684-4BBB-9F6B-2C9E8030606C@aatal-apotheke.de> > Am 11.12.2018 um 00:50 schrieb Clinton Mead : > > > One can write a function > Eq a => ((a -> Bool) -> a) -> [a] > that enumerates the elements of the set. Because we have universal quantification, this list can not be infinite. Which makes sense, topologically: These so-called searchable sets are topologically compact, and the Eq constraint means the space is discrete. Compact subsets of a discrete space are finite. > > Olaf > > > Olaf (or anyone else), can you help me out here and write this function, with some example inputs and outputs? Below is my testing version of the searchable sets. The names differ slightly from the ones in the infinite-search package. The function you are looking for is called 'enumerate' -- Olaf module Searchable where import Control.Monad import qualified Control.Applicative import Data.Set (Set) import qualified Data.Set as Set -- Escardo's Monad for non-empty compact subsets. -- Data type of searchable subsets of a. -- Specification: -- For every predicate p :: a -> Bool and searchable set k :: S a, -- there exists some x in k with p(x) if and only if p(find k p). newtype S a = Finder ((a -> Bool) -> a) find :: S a -> (a -> Bool) -> a find (Finder f) p = f p exists :: S a -> (a -> Bool) -> Bool exists (Finder f) p = p (f p) forall :: S a -> (a -> Bool) -> Bool forall k p = not $ exists k (not.p) instance Functor S where fmap g (Finder f) = Finder (\p -> g(f(p.g))) singleton :: a -> S a singleton x = Finder (const x) -- Compact subsets of totally ordered types have least and greatest elements. isSingleton :: (Ord a) => S a -> Bool isSingleton k = (inf k id) >= (sup k id) doubleton :: a -> a -> S a doubleton x y = Finder (\p -> if p x then x else y) -- doubleton x y = finite [x,y] finite :: [a] -> S a finite [] = error "{} is compact, but empty" finite [x] = singleton x finite (x:xs) = (singleton x) \/ (finite xs) -- the union of compactly many compact sets is compact. -- union (doubleton x y) = x \/ y union :: S (S a) -> S a union (Finder ff) = Finder (\p -> let Finder f = ff (\k -> exists k p) in f p) -- binary union. Generalises doubleton. infixl 5 \/ (\/) :: S a -> S a -> S a (Finder f) \/ (Finder f') = Finder (\p -> if p (f p) then f p else f' p) instance Monad S where return = singleton k >>= f = union $ fmap f k instance Control.Applicative.Applicative S where pure = return (<*>) = ap -- Searchable subsets of discrete spaces are clopen, -- searchable subsets of Hausdorff spaces are closed. -- Notice that -- -- @ -- (flip member) :: S a -> (a -> Bool) -- @ -- -- This predicate returns 'False' iff the element is not member of the set -- and 'True' for every element of the set, provided that equality is decidable. member :: (Eq a) => a -> S a -> Bool x `member` k = exists k (x ==) -- output the part of the list that is in the compact set. filterS :: (Eq a) => S a -> [a] -> [a] filterS k = filter (flip member k) -- In every sober space, the intersection of a compact set -- with a closed set is compact (but may be empty). -- If the intersection is not empty, this function will compute it. intersect :: (a -> Bool) -> S a -> S a intersect c k = Finder (\p -> find k (\x -> p x && c x)) -- instances of Ord have searchable subsets that can be well-ordered. sort :: (Ord a) => S a -> Set a sort k = let i = inf k id extend current_largest set = if y > current_largest then extend y (Set.insert y set) else set where y = find k (current_largest <) in extend i (Set.singleton i) -- instances of Eq have searchable subsets that can be enumerated. O(n^2). -- The Eq constraint means the underlying space is discrete, -- and compact subsets of a discrete space are finite. enumerate :: (Eq a) => S a -> [a] enumerate k = let another p = let y = find k p in if p y then Just y else Nothing Just x0 = another (const True) extend enumeration = case another (not.flip elem enumeration) of Nothing -> enumeration Just e -> extend (e:enumeration) in extend [x0] -- fold of a function into a commutative monoid. -- Since searchable sets have no intrinsic order, -- the result of the fold is only well-defined if the monoid is commutative. foldMapEq :: (Monoid m, Eq m) => (a -> m) -> S a -> m foldMapEq f k = mconcat (enumerate (fmap f k)) -- show at most 8 elements of a compact set. instance (Show a, Ord a) => Show (S a) where show k = begin $ take 8 $ Set.elems $ sort k where begin l | length l < 8 = show l | otherwise = (init $ show l)++", ...]" -- Equality lifts to searchable subsets, -- because the subset relation is computable. instance (Eq a) => Eq (S a) where k == k' = let subset k k' = forall k (\x -> member x k') in (subset k k') && (subset k' k) -- A continuous map on a compact set attains its infimum and supremum. inf :: (Ord b) => S a -> (a -> b) -> a inf k@(Finder f) g = f (\x -> forall k (\y -> g(x) <= g(y))) sup :: (Ord b) => S a -> (a -> b) -> a sup k@(Finder f) g = f (\x -> forall k (\y -> g(y) <= g(x))) -- Hausdorff distance, given a metric. -- This is a special case of the so-called Egli-Milner relation lifting. dHaus :: (Ord r) => (a -> a -> r) -> S a -> S a -> r dHaus d k k' = let h k1 k2 = i (sup k1 i) where i = \x -> d x (inf k2 (d x)) in max (h k k') (h k' k) {-- Examples --} -- [()] = ℕ ∪ {∞} is compact. nats :: S [()] nats = Finder f where f p = if p [] then [] else ():f (\n -> p (():n)) -- Cantor space (ℕ → 2) is a compact subspace of Baire space (ℕ → ℕ). cantor :: S [Int] cantor = sequence $ repeat $ doubleton 0 1 -- Drinker's paradox: -- For evers non-empty compact pub, -- there is a person x such that -- if x drinks, then everybody in the pub drinks. drinker :: S person -> (person -> Bool) -> person drinker in_pub drinks = find in_pub (not.drinks) From seph at codex.scot Tue Dec 11 19:27:21 2018 From: seph at codex.scot (Seph Shewell Brockway) Date: Tue, 11 Dec 2018 19:27:21 +0000 Subject: [Haskell-cafe] Fwd: [Haskell-beginners] monad and variable result In-Reply-To: <5C0FDDB0.3040207@oca.eu> References: <5C0E40B7.6010909@oca.eu> <5C0E75C8.5000501@oca.eu> <20181210161939.5qo4cqp4ddggqymm@leviathan> <5C0E9D16.9040500@oca.eu> <20181210185636.ygmgdxgscbevwdk5@leviathan> <5C0FDDB0.3040207@oca.eu> Message-ID: <20181211192721.4tomk7vz2354zdr4@leviathan> On Tue, Dec 11, 2018 at 04:54:24PM +0100, Damien Mattei wrote: > but the question rest entire :how can i get the loat number from all this? > > i have a Main that looks like this: > > > main :: IO () > --main :: Int > main = > > do > conn <- connect defaultConnectInfo > { connectHost = "moita", > connectUser = "mattei", > connectPassword = "sidonie2", > connectDatabase = "sidonie" } > > > > -- first we get the N°BD from sidonie > > let name = "A 20" > > let noBD_IO = getBD conn name > > -- putStrLn $ show $ read $ Text.unpack noBD_IO > > close conn > > print "Exit." Within a do block, ‘let’ statements are for pure values, while for monadic ones you bind a variable with <-, for example with noBD <- getBD conn name whatever This is do-notation, which desugars to getBD conn name >>= \noBD -> whatever In this context, >>= has type signature (>>=) :: IO a -> (a -> IO b) -> IO b In fact it works for any monad, but let’s stick to IO for now. If we look at this function type a bit, we see that it takes a monadic computation and feeds it into a function that takes a _pure_ value. In this case the function in question is your print statement: putStrLn . show :: Show a => a -> IO () (There is actually a builtin function called print that does exactly this.) Its input type is a, not IO a, so the result of getBD can’t be used as-is, but >>= (pronounced ‘bind’) enables the return value of the IO computation to be fed into the new function, returning a new monadic computation representing the combination of the two original ones. If you think about it, the ‘inescapable’ nature of the IO monad makes sense: if a function is pure, it can’t have side effects, and therefore it can’t use any data that it has to execute a side effect to get. However, the fact that the main function has a monadic type IO (), combined with the ability to ‘chain’ monadic computations as described above, means that you don’t ever need to escape the IO monad; you can simply ‘pull’ the pure functions you need _into_ the monad instead. If I may make a suggestion, I would avoid using do-notation at all until you’re a bit more comfortable with how monadic computations work, and how Haskell handles IO. To someone used to imperative programming, it can be more confusing that helpful, as it allows you to write something that looks and feels a lot like imperative code but differs from it in crucial ways. Get comfortable with using the monadic operators >> and >>= directly, and only then switch back to do-notation. Or don’t—personally I prefer not to use do-notation at all. Regards, Seph -- Seph Shewell Brockway, BSc MSc (Glas.) From mattei at oca.eu Wed Dec 12 10:14:19 2018 From: mattei at oca.eu (Damien Mattei) Date: Wed, 12 Dec 2018 11:14:19 +0100 Subject: [Haskell-cafe] Fwd: [Haskell-beginners] monad and variable result In-Reply-To: <20181211192721.4tomk7vz2354zdr4@leviathan> References: <5C0E40B7.6010909@oca.eu> <5C0E75C8.5000501@oca.eu> <20181210161939.5qo4cqp4ddggqymm@leviathan> <5C0E9D16.9040500@oca.eu> <20181210185636.ygmgdxgscbevwdk5@leviathan> <5C0FDDB0.3040207@oca.eu> <20181211192721.4tomk7vz2354zdr4@leviathan> Message-ID: <5C10DF7B.8030702@oca.eu> thank you a lot Seph for all those explanations, i read them carefully and finally come to this: getBD conn name >>= \noBD -> ((putStrLn . show) noBD) that print it on the screen in main but it remains a last step ,how can get it in a Float variable? Damien Le 11/12/2018 20:27, Seph Shewell Brockway a écrit : > On Tue, Dec 11, 2018 at 04:54:24PM +0100, Damien Mattei wrote: >> but the question rest entire :how can i get the loat number from all this? >> >> i have a Main that looks like this: >> >> >> main :: IO () >> --main :: Int >> main = >> >> do >> conn <- connect defaultConnectInfo >> { connectHost = "moita", >> connectUser = "mattei", >> connectPassword = "sidonie2", >> connectDatabase = "sidonie" } >> >> >> >> -- first we get the N°BD from sidonie >> >> let name = "A 20" >> >> let noBD_IO = getBD conn name >> >> -- putStrLn $ show $ read $ Text.unpack noBD_IO >> >> close conn >> >> print "Exit." > > Within a do block, ‘let’ statements are for pure values, while > for monadic ones you bind a variable with <-, for example with > > noBD <- getBD conn name > whatever > > This is do-notation, which desugars to > > getBD conn name >>= \noBD -> whatever > > In this context, >>= has type signature > > (>>=) :: IO a -> (a -> IO b) -> IO b > > In fact it works for any monad, but let’s stick to IO for now. If we > look at this function type a bit, we see that it takes a monadic > computation and feeds it into a function that takes a _pure_ value. > In this case the function in question is your print statement: > > putStrLn . show :: Show a => a -> IO () > > (There is actually a builtin function called print that does exactly > this.) Its input type is a, not IO a, so the result of getBD can’t be > used as-is, but >>= (pronounced ‘bind’) enables the return value of the > IO computation to be fed into the new function, returning a new monadic > computation representing the combination of the two original ones. > > If you think about it, the ‘inescapable’ nature of the IO monad makes > sense: if a function is pure, it can’t have side effects, and therefore > it can’t use any data that it has to execute a side effect to get. > However, the fact that the main function has a monadic type IO (), > combined with the ability to ‘chain’ monadic computations as described > above, means that you don’t ever need to escape the IO monad; you can > simply ‘pull’ the pure functions you need _into_ the monad instead. > > If I may make a suggestion, I would avoid using do-notation at all until > you’re a bit more comfortable with how monadic computations work, and > how Haskell handles IO. To someone used to imperative programming, it > can be more confusing that helpful, as it allows you to write something > that looks and feels a lot like imperative code but differs from it in > crucial ways. Get comfortable with using the monadic operators >> and >>= > directly, and only then switch back to do-notation. Or don’t—personally > I prefer not to use do-notation at all. > > Regards, > > Seph > -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From m at jaspervdj.be Wed Dec 12 20:16:21 2018 From: m at jaspervdj.be (Jasper Van der Jeugt) Date: Wed, 12 Dec 2018 21:16:21 +0100 Subject: [Haskell-cafe] ZuriHac 2019 takes place 14 to 16 June in Zurich, Switzerland Message-ID: <20181212201621.GA6421@colony6.localdomain> Hello Friends of Haskell, It is our great pleasure to announce that the next ZuriHac will take place from Friday the 14th to Sunday the 16th of June 2019. It will be hosted at the Hochschule Rapperswil on the shores of beautiful Lake Zurich. This will mark the 8th anniversary of ZuriHac since our beginnings in 2010. The Zurich Haskell Hackathon is a free, international, grassroots, and collaborative coding festival. Our goal is to connect Haskellers, expand the community, learn things from each other, and to work on Haskell libraries, tools, and infrastructure. This year, we will enjoy keynotes from: - Simon Peyton Jones - Susan Potter - Richard Eisenberg - Ryan Trinkle More keynote speakers will be announced. The event is open to any experience level, from beginners to gurus. We want to make a special effort to ensure that the event is welcoming and accessible to people completely new to Haskell. That is why we are super excited that, Julie Moronuki, co-author of Haskell Programming from first principles [1] and Joy of Haskell [2], has kindly agreed to teach a beginners course in one of the classrooms we have available. Additionally, there will be mentors that you can approach during the whole event with any Haskell-related questions. This is a great opportunity to meet your fellow Haskellers in real life, find new contributors for your project, improve existing libraries and tools or even start new ones! We will have space for over 400 attendees. Registration is free and will open on 26th of December, as a late holiday present to Haskellers around the globe. You can find this information and more on our website: https://zfoh.ch/zurihac2019 We would also like to thank our sponsors Digital Asset [3], DFINITY [4] and HSR [5] for their strong commitment to the Haskell community and for supporting this great event! Looking forward to seeing you there, The Zurich Friends of Haskell association [6] [1]: https://www.goodreads.com/book/show/25587599-haskell-programming [2]: https://joyofhaskell.com/ [3]: https://digitalasset.com/careers.html [4]: https://dfinity.org/jobs [5]: https://www.hsr.ch/ [6]: https://zfoh.ch/ From george at wils.online Thu Dec 13 03:35:15 2018 From: george at wils.online (George Wilson) Date: Thu, 13 Dec 2018 13:35:15 +1000 Subject: [Haskell-cafe] Call for Haskell.org Committee Nominations Message-ID: Dear Haskellers, It is time to put out a call for new nominations (typically but not necessarily self-nominations) to the haskell.org committee. We have one member of our committee due for retirement -- our chair Gershom Bazerman. To nominate yourself, please send an email to committee at haskell.org by the 7th of January, 2019. Retiring members are eligible to re-nominate themselves. Please feel free to include any information about yourself that you think will help us to make a decision. The Haskell.org committee serves as a board of directors for Haskell.org, a 501(c)3 nonprofit which oversees technical and financial resources related to Haskell community infrastructure. Being a member of the committee does not necessarily require a significant amount of time, but committee members should aim to be responsive during discussions when the committee is called upon to make a decision. Strong leadership, communication, and judgement are very important characteristics for committee members. The role is about setting policy, providing direction/guidance for Haskell.org infrastructure, planning for the long term, and being fiscally responsible with the Haskell.org funds (and donations). As overseers for policy regarding the open source side of Haskell, committee members must also be able to set aside personal or business related bias and make decisions with the good of the open source Haskell community in mind. We seek a broad representation from different segments of the Haskell world -- including but not limited to those focused on education, those focused on industrial applications, those with background in organizing users-groups, and those focused directly on our technical infrastructure. More details about the committee's roles and responsibilities are on https://wiki.haskell.org/Haskell.org_committee If you have any questions about the process, please feel free to e-mail us at committee at haskell.org, or contact one of us individually. Regards, George Wilson From gershomb at gmail.com Thu Dec 13 17:09:41 2018 From: gershomb at gmail.com (Gershom B) Date: Thu, 13 Dec 2018 12:09:41 -0500 Subject: [Haskell-cafe] Announce: Haskell Platform 8.6.3 Message-ID: On behalf of the Haskell Platform team, I'm happy to announce the release of Haskell Platform 8.6.3 Now available at https://www.haskell.org/platform/ This includes GHC 8.6.3, cabal-install 2.4.1.0, and stack 1.9.3. This is the first platform released in the 8.6 series, as we have waited until a number of bugfix ghc releases stabilized things across all core platforms (linux, os x, windows). A full list of contents is available at https://www.haskell.org/platform/contents.html The list of GHC changes is available at: https://ghc.haskell.org/trac/ghc/blog/ghc-8.6.1-released https://ghc.haskell.org/trac/ghc/blog/ghc-8.6.2-released https://ghc.haskell.org/trac/ghc/blog/ghc-8.6.3-released A list of cabal changes is available at: https://hackage.haskell.org/package/cabal-install-2.4.1.0/changelog A list of stack changes is available at: https://docs.haskellstack.org/en/stable/ChangeLog/#v193 There are a number of important changes in this release, with more changes planned in the future. First: Win32 builds are working again and provided. Thanks to all the folks (especially Tamar) who helped sort out the build issues on that platform. Second, only core builds are provided, not "full" builds. This release is the first one where cabal-install warns on legacy commands and asks users to either use the v1-prefix for them or the v2/new prefix to move to the new-build system. As such, providing additional global packages outside of the core set now makes even less sense than in the past, where we had been already discouraging it for some time. Finally, there are no linux generic builds provided, and instead we recommend use of the ghcup tool (https://github.com/haskell/ghcup/) in combination with the stack install script. We feel this gives a smoother and better experience than the existing install process, being less invasive (not requiring root) and more flexible (by running ghc's own configure script it can better detect differences in configuration between distros). What does this all mean for the future of the platform? What I would like to move towards is the following. First: replacing the mac installer by ghcup as well in the near future. While a native installer has its advantages, the same reasons that ghcup is recommended on linux hold for mac as well, although with somewhat less force. Because of how Windows works, the difficulties of moving from a native installer are much more real, and we would anticipate keeping a native installer for the time being. Second: with the platform installers (or recommended installers) now really a delivery mechanism for core binaries and nothing else, to move to split the platform into two components. A) a set of recommended install instructions for major platforms (and a native windows installer), and B) a set of recommended and known-compatible packages which cover most "extended standard-lib" bases and which we again grow much more freely, as in the past. This will require some redesign and reconceptualization of the website, and would be a great opportunity for people that want to chip-in to move things forward to get involved. Please reach out if you'd like to lend a hand! Happy Haskell Hacking all, Gershom From mattei at oca.eu Fri Dec 14 10:49:45 2018 From: mattei at oca.eu (Damien Mattei) Date: Fri, 14 Dec 2018 11:49:45 +0100 Subject: [Haskell-cafe] fmap use Message-ID: <5C138AC9.50200@oca.eu> hello again, another question with Haskell, again with my database but that is again related to Monads: i have this code in main: rows <- query_ conn "SELECT Nom,distance FROM AngularDistance WHERE distance > 0.000278" let lg = Prelude.length rows let tst = if lg > 1 then "some" else "one or zero" it compiles and i assume it works, and i have a new (for those that have follow my previous posts) function like this one: -- this function will return the list of N°BD from WDS for a given name -- note: there could be multiple result for a given name in WDS due to components getBD_WDS :: Connection -> String -> IO Float getBD_WDS conn name = trace "Entering getBD_WDS" noBDfp where qry_head = "select DNUM from WDS where DISC = ?" :: Query bd_rows :: IO [Only Text] bd_rows = query conn qry_head (Only (name::String)) lg = fmap Prelude.length bd_rows -- tst = if (fmap lg) > 1 then "some" else "one or zero" noBDtxt :: IO Text -- noBDtxt = trace "lg " (fmap (fromOnly . Prelude.head) bd_rows) noBDtxt = (fmap (fromOnly . Prelude.head) bd_rows) -- noBDstr :: String -- noBDstr = Text.unpack noBDtxt noBDstr :: IO String noBDstr = fmap Text.unpack noBDtxt -- noBDfp = read $ noBDstr :: Float noBDfp :: IO Float noBDfp = trace "Exiting getBD" (fmap read noBDstr) the problem is that first i noticed that in a function to make working the same code than in Main i had to had almost always fmap before the line, i admit ,even if i'm teacher in functional programming in Scheme at University, i begin in Haskell and i don't always understand what i'm using, i try to learn it by instinct even if sometimes i read pages about Functor and Monads i have no time to get in the Mathematics theoretical knowledge behind Haskell, i try to learn by getting some solutions in Haskell-cafe and it works, i know now a lot more about Haskell than 2 weeks ago,so.... if someon could explain me a few more about fmap or just give what i must place in my function instead of let lg = Prelude.length rows let tst = if lg > 1 then "some" else "one or zero" i replace this in the function by: lg = fmap Prelude.length bd_rows OK for compilation, but then tst = if lg > 1 then "some" else "one or zero" does not compile: *Main> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:80:18: error: • No instance for (Ord (IO Int)) arising from a use of ‘>’ • In the expression: lg > 1 In the expression: if lg > 1 then "some" else "one or zero" In an equation for ‘tst’: tst = if lg > 1 then "some" else "one or zero" | 80 | tst = if lg > 1 then "some" else "one or zero" | ^^^^^^ UpdateSidonie.hs:80:23: error: • No instance for (Num (IO Int)) arising from the literal ‘1’ • In the second argument of ‘(>)’, namely ‘1’ In the expression: lg > 1 In the expression: if lg > 1 then "some" else "one or zero" | 80 | tst = if lg > 1 then "some" else "one or zero" | ^ Failed, no modules loaded. and even the "fmap miraculous function" as i call it no more works: tst = if (fmap lg) > 1 then "some" else "one or zero" Prelude> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:80:24: error: • Couldn't match expected type ‘a0 -> b0’ with actual type ‘IO Int’ • In the first argument of ‘fmap’, namely ‘lg’ In the first argument of ‘(>)’, namely ‘(fmap lg)’ In the expression: (fmap lg) > 1 | 80 | tst = if (fmap lg) > 1 then "some" else "one or zero" | ^^ Failed, no modules loaded. a solution to this proble i think , will help me a lot, i sticked with problems in haskell i would have already solved in Scheme or Python, that's really discouraging me of using Haskell, i'm obstinating myself because i really think it's a great language that push the programming to high levels of abstractions but for now it's a bit a nightmare, i must admit it... -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk Fri Dec 14 11:22:38 2018 From: tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk (Tom Ellis) Date: Fri, 14 Dec 2018 11:22:38 +0000 Subject: [Haskell-cafe] fmap use In-Reply-To: <5C138AC9.50200@oca.eu> References: <5C138AC9.50200@oca.eu> Message-ID: <20181214112238.nkoyagudmjxyafu2@weber> On Fri, Dec 14, 2018 at 11:49:45AM +0100, Damien Mattei wrote: > another question with Haskell, again with my database but that is again > related to Monads: Damien, it's very hard to read your posts because they consist of snippets of code interspersed with commentary. You'll probably get much better responses if you post single, very small, well-formatted examples of sample code. Anyway, the ultimate answer to your query is "use do-notation". Your getBS_WDS would be clearer written something like: ``` getBD_WDS :: Connection -> String -> IO Float getBD_WDS conn name = do let qry_head = "select DNUM from WDS where DISC = ?" :: Query bd_rows <- query conn qry_head (Only name) let noBDtxt :: Text noBDtxt = fromOnly (Prelude.head bd_rows) noBDstr :: String noBDstr = Text.unpack noBDtxt noBDfp :: Float noBDfp = read noBDstr return noBDfp ``` Tom From tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk Fri Dec 14 11:42:56 2018 From: tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk (Tom Ellis) Date: Fri, 14 Dec 2018 11:42:56 +0000 Subject: [Haskell-cafe] fmap use In-Reply-To: <20181214112238.nkoyagudmjxyafu2@weber> References: <5C138AC9.50200@oca.eu> <20181214112238.nkoyagudmjxyafu2@weber> Message-ID: <20181214114256.iqcbivzb4d3qjbt4@weber> On Fri, Dec 14, 2018 at 11:22:38AM +0000, Tom Ellis wrote: > On Fri, Dec 14, 2018 at 11:49:45AM +0100, Damien Mattei wrote: > > another question with Haskell, again with my database but that is again > > related to Monads: > > Damien, it's very hard to read your posts because they consist of snippets > of code interspersed with commentary. You'll probably get much better > responses if you post single, very small, well-formatted examples of sample > code. > > Anyway, the ultimate answer to your query is "use do-notation". Your > getBS_WDS would be clearer written something like: Ah, I see now why you were determined to use `fmap`. Seph recommended it to you I would avoid using do-notation at all until you’re a bit more comfortable with how monadic computations work, and how Haskell handles IO. To someone used to imperative programming, it can be more confusing that helpful, as it allows you to write something that looks and feels a lot like imperative code but differs from it in crucial ways. Get comfortable with using the monadic operators >> and >>= directly, and only then switch back to do-notation. Or don’t—personally I prefer not to use do-notation at all. -- Seph Shewell Brockway https://mail.haskell.org/pipermail/haskell-cafe/2018-December/130367.html I have to say I have completely the opposite position to Seph. If you try to write code in IO as a beginner without using do-notation you are in for a world of pain. Damien, I would suggest you write (very) small practice programs using both Seph's advice and mine and see which style you prefer and which helps you learn Haskell quicker. Tom From tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk Fri Dec 14 11:45:44 2018 From: tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk (Tom Ellis) Date: Fri, 14 Dec 2018 11:45:44 +0000 Subject: [Haskell-cafe] fmap use In-Reply-To: <20181214112238.nkoyagudmjxyafu2@weber> References: <5C138AC9.50200@oca.eu> <20181214112238.nkoyagudmjxyafu2@weber> Message-ID: <20181214114544.ox7gxgqi5j7dwqjw@weber> On Fri, Dec 14, 2018 at 11:22:38AM +0000, Tom Ellis wrote: > On Fri, Dec 14, 2018 at 11:49:45AM +0100, Damien Mattei wrote: > > another question with Haskell, again with my database but that is again > > related to Monads: > > Damien, it's very hard to read your posts because they consist of snippets > of code interspersed with commentary. You'll probably get much better > responses if you post single, very small, well-formatted examples of sample > code. > > Anyway, the ultimate answer to your query is "use do-notation". Your > getBS_WDS would be clearer written something like: And ultimately I think you wanted to do something with lg and tst: ``` getBD_WDS :: Connection -> String -> IO Float getBD_WDS conn name = do let qry_head = "select DNUM from WDS where DISC = ?" :: Query bd_rows <- query conn qry_head (Only name) let lg = Prelude.length bd_rows putStrLn (if lg > 1 then "some" else "one or zero") let noBDtxt :: Text noBDtxt = fromOnly (Prelude.head bd_rows) noBDstr :: String noBDstr = Text.unpack noBDtxt noBDfp :: Float noBDfp = read noBDstr return noBDfp ``` From ducis_cn at 126.com Fri Dec 14 12:56:28 2018 From: ducis_cn at 126.com (ducis) Date: Fri, 14 Dec 2018 20:56:28 +0800 (CST) Subject: [Haskell-cafe] How to unify these three types with identical structures into one definition? In-Reply-To: References: Message-ID: <28219dbc.af97.167acca2714.Coremail.ducis_cn@126.com> Hello, Say I have a certain type for parse trees: data Expr = Var String | Enclosed String Expr String | Prefix Expr Expr | Ternary Expr String Expr String Expr deriving (Show,Eq,Ord,Generic)--,Typeable) Then I want a new type where every occurence of "Expr" definition changed to "[Expr]": data ExprL = VarL String | EnclosedL String [Expr] String | PrefixL [Expr] [Expr] | TernaryL [Expr] String [Expr] String [Expr] deriving (Show,Eq,Ord,Generic) Sometimes, I also want to use a DList instead of list. data ExprD = VarD String | EnclosedD String (DList Expr) String | PrefixD (DList Expr) (DList Expr) | TernaryD (DList Expr) String (DList Expr) String (DList Expr) deriving (Show,Eq,Ord,Generic) They have exactly the same structure, is there a way to unify the three definitions into one? Furthurmore, is it possible to generalise the latter two for all Functors ? Thanks, ducis -------------- next part -------------- An HTML attachment was scrubbed... URL: From to_br at uni-bremen.de Fri Dec 14 13:08:48 2018 From: to_br at uni-bremen.de (Tobias Brandt) Date: Fri, 14 Dec 2018 14:08:48 +0100 Subject: [Haskell-cafe] How to unify these three types with identical structures into one definition? In-Reply-To: <28219dbc.af97.167acca2714.Coremail.ducis_cn@126.com> References: <28219dbc.af97.167acca2714.Coremail.ducis_cn@126.com> Message-ID: Hello, my adhoc solution would be to add a type parameter: data ExprG a = Var String   | Enclosed String a String   | Prefix a a   | Ternary a String a String a deriving Show type Expr = ExprG (ExprG ()) type ExprL = ExprG [Expr] Cheers, Tobias On 12/14/18 1:56 PM, ducis wrote: > Hello, > > Say I have a certain type for parse trees: > data Expr = Var String >    | Enclosed String Expr String >    | Prefix Expr Expr >    | Ternary Expr String Expr String Expr >    deriving (Show,Eq,Ord,Generic)--,Typeable) > > Then I want a new type where every occurence of "Expr" definition > changed to "[Expr]": > data ExprL = VarL String >    | EnclosedL String [Expr] String >    | PrefixL [Expr] [Expr] >    | TernaryL [Expr] String [Expr] String [Expr] >    deriving (Show,Eq,Ord,Generic) > > Sometimes, I also want to use a DList instead of list. > data ExprD = VarD String >    | EnclosedD String (DList Expr) String >    | PrefixD (DList Expr) (DList Expr) >    | TernaryD (DList Expr) String (DList Expr) String (DList Expr) >    deriving (Show,Eq,Ord,Generic) > > They have exactly the same structure, is there a way to unify the > three definitions into one? > Furthurmore, is it possible to generalise the latter two for all > Functors ? > > Thanks, > ducis > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From migmit at gmail.com Fri Dec 14 13:17:48 2018 From: migmit at gmail.com (MigMit) Date: Fri, 14 Dec 2018 14:17:48 +0100 Subject: [Haskell-cafe] How to unify these three types with identical structures into one definition? In-Reply-To: References: <28219dbc.af97.167acca2714.Coremail.ducis_cn@126.com> Message-ID: You probably mean newtype Expr = Expr (ExprG Expr) Az iPademről küldve 2018. dec. 14. dátummal, 14:08 időpontban Tobias Brandt írta: > Hello, > > my adhoc solution would be to add a type parameter: > > data ExprG a = Var String > | Enclosed String a String > | Prefix a a > | Ternary a String a String a deriving Show > > > type Expr = ExprG (ExprG ()) > > type ExprL = ExprG [Expr] > > > Cheers, > > Tobias > > > >> On 12/14/18 1:56 PM, ducis wrote: >> Hello, >> >> Say I have a certain type for parse trees: >> data Expr = Var String >> | Enclosed String Expr String >> | Prefix Expr Expr >> | Ternary Expr String Expr String Expr >> deriving (Show,Eq,Ord,Generic)--,Typeable) >> >> Then I want a new type where every occurence of "Expr" definition changed to "[Expr]": >> data ExprL = VarL String >> | EnclosedL String [Expr] String >> | PrefixL [Expr] [Expr] >> | TernaryL [Expr] String [Expr] String [Expr] >> deriving (Show,Eq,Ord,Generic) >> >> Sometimes, I also want to use a DList instead of list. >> data ExprD = VarD String >> | EnclosedD String (DList Expr) String >> | PrefixD (DList Expr) (DList Expr) >> | TernaryD (DList Expr) String (DList Expr) String (DList Expr) >> deriving (Show,Eq,Ord,Generic) >> >> They have exactly the same structure, is there a way to unify the three definitions into one? >> Furthurmore, is it possible to generalise the latter two for all Functors ? >> >> Thanks, >> ducis >> >> >> _______________________________________________ >> Haskell-Cafe mailing list >> To (un)subscribe, modify options or view archives go to: >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> Only members subscribed via the mailman list are allowed to post. > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattei at oca.eu Fri Dec 14 14:36:03 2018 From: mattei at oca.eu (Damien Mattei) Date: Fri, 14 Dec 2018 15:36:03 +0100 Subject: [Haskell-cafe] (SPAM 3)Re: fmap use In-Reply-To: <20181214114544.ox7gxgqi5j7dwqjw@weber> References: <5C138AC9.50200@oca.eu> <20181214112238.nkoyagudmjxyafu2@weber> <20181214114544.ox7gxgqi5j7dwqjw@weber> Message-ID: <5C13BFD3.1050804@oca.eu> ok Elis i tried again, first ,as i am familiar with λ expressions i can use both do syntactic sugar or the other form with λ. so itried you code,surpringly it compiles but when i launch it the function can not print somethin on screen, i assume it is because function are pure in haskell, nor with putStrln or Debug.trace: getBD_WDS :: Connection -> String -> IO Float getBD_WDS conn name = do let qry_head = "select DNUM from WDS where DISC = ?" :: Query bd_rows <- query conn qry_head (Only name) let lg = Prelude.length bd_rows -- putStrLn (if lg > 1 then "some" else "one or zero") let tst = trace (if lg > 1 then "some" else "one or zero") (if lg > 1 then "some" else "one or zero") -- let noBDtxt :: Text let noBDtxt = fromOnly (Prelude.head bd_rows) -- noBDstr :: String let noBDstr = Text.unpack noBDtxt -- noBDfp :: Float let noBDfp = read noBDstr return noBDfp in fact due to lazy evaluation i'm not sure it compiles all the code because a more simple example give compilation errors: getLstBD_WDS :: Connection -> String -> IO Int getLstBD_WDS conn name = do let qry_head = "select DNUM from WDS where DISC = ?" :: Query bd_rows <- query conn qry_head (Only name) let lg = Prelude.length bd_rows return lg Prelude> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:123:14: error: • Ambiguous type variable ‘r0’ arising from a use of ‘query’ prevents the constraint ‘(QueryResults r0)’ from being solved. Probable fix: use a type annotation to specify what ‘r0’ should be. These potential instances exist: instance Result a => QueryResults (Only a) -- Defined in ‘Database.MySQL.Simple.QueryResults’ instance (Result a, Result b) => QueryResults (a, b) -- Defined in ‘Database.MySQL.Simple.QueryResults’ instance (Result a, Result b, Result c) => QueryResults (a, b, c) -- Defined in ‘Database.MySQL.Simple.QueryResults’ ...plus 21 others (use -fprint-potential-instances to see them all) • In a stmt of a 'do' block: bd_rows <- query conn qry_head (Only name) In the expression: do let qry_head = ... bd_rows <- query conn qry_head (Only name) let lg = Prelude.length bd_rows return lg In an equation for ‘getLstBD_WDS’: getLstBD_WDS conn name = do let qry_head = ... bd_rows <- query conn qry_head (Only name) let lg = ... .... | 123 | bd_rows <- query conn qry_head (Only name) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Failed, no modules loaded. Le 14/12/2018 12:45, Tom Ellis a écrit : > On Fri, Dec 14, 2018 at 11:22:38AM +0000, Tom Ellis wrote: >> On Fri, Dec 14, 2018 at 11:49:45AM +0100, Damien Mattei wrote: >>> another question with Haskell, again with my database but that is again >>> related to Monads: >> >> Damien, it's very hard to read your posts because they consist of snippets >> of code interspersed with commentary. You'll probably get much better >> responses if you post single, very small, well-formatted examples of sample >> code. >> >> Anyway, the ultimate answer to your query is "use do-notation". Your >> getBS_WDS would be clearer written something like: > > And ultimately I think you wanted to do something with lg and tst: > > ``` > getBD_WDS :: Connection -> String -> IO Float > getBD_WDS conn name = do > let qry_head = "select DNUM from WDS where DISC = ?" :: Query > > bd_rows <- query conn qry_head (Only name) > > let lg = Prelude.length bd_rows > > putStrLn (if lg > 1 then "some" else "one or zero") > > let noBDtxt :: Text > noBDtxt = fromOnly (Prelude.head bd_rows) > > noBDstr :: String > noBDstr = Text.unpack noBDtxt > > noBDfp :: Float > noBDfp = read noBDstr > > return noBDfp > ``` > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. > -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From monkleyon at gmail.com Fri Dec 14 14:51:51 2018 From: monkleyon at gmail.com (MarLinn) Date: Fri, 14 Dec 2018 15:51:51 +0100 Subject: [Haskell-cafe] How to unify these three types with identical structures into one definition? In-Reply-To: <28219dbc.af97.167acca2714.Coremail.ducis_cn@126.com> References: <28219dbc.af97.167acca2714.Coremail.ducis_cn@126.com> Message-ID: <8c8e939b-521f-abbd-4a1d-32e2c4a71b5f@gmail.com> Hi Ducis, you can parametrise over type variables of other kinds than just *. If what you write is really what you want, the most straightforward answer is simply data ExprG f     = Var VarName     | Enclosed VarName (f Expr) VarName     | Prefix  (f Expr) (f Expr)     | Ternary (f Expr) VarName (f Expr) VarName (f Expr) type Expr  = ExprG Identity -- From Data.Functor.Identity type ExprL = ExprG [] type ExprD = ExprG DList There is no mention of the word "functor" because you will have to add that constraint to the usage sites. Downside: notice that the deriving clauses are gone because the instances aren't as easy to derive any more. Even the simplest and most harmless way I know to get that possibility back involves two language extensions: StandaloneDeriving and FlexibleInstances. With those you can write deriving instance Show (ExprG Identity) deriving instance Show (ExprG []) deriving instance Show (ExprG DList) deriving instance Eq   (ExprG Identity) : I suspect though that what you actually want, but didn't write, is more along the lines of data ExprL = … | EnclosedL VarName [ExprL] VarName | … -- using ExprL instead of Expr on the right side data ExprD = … | EnclosedD VarName (DList ExprD) VarName | … -- using ExprD instead of Expr on the right side The good news is that if you have the first solution, this step is rather simple. Because you can just use replace Expr with ExprG f again: data ExprG f = Var VarName     | Enclosed VarName (f (ExprG f)) VarName     | Prefix   (f (ExprG f)) (f (ExprG f))     | Ternary (f (ExprG f)) VarName (f (ExprG f)) VarName (f (ExprG f)) The better news is that although this looks repetitive and hard to read, it's well on the way to discovering the magic of the Free Monad. Hope this helps. Cheers, MarLinn -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Fri Dec 14 15:14:17 2018 From: allbery.b at gmail.com (Brandon Allbery) Date: Fri, 14 Dec 2018 10:14:17 -0500 Subject: [Haskell-cafe] (SPAM 3)Re: fmap use In-Reply-To: <5C13BFD3.1050804@oca.eu> References: <5C138AC9.50200@oca.eu> <20181214112238.nkoyagudmjxyafu2@weber> <20181214114544.ox7gxgqi5j7dwqjw@weber> <5C13BFD3.1050804@oca.eu> Message-ID: On Fri, Dec 14, 2018 at 9:36 AM Damien Mattei wrote: > in fact due to lazy evaluation i'm not sure it compiles all the code > because a more simple example give compilation errors: > Er? Lazy evaluation has nothing to do with what gets compiled; the only way the compiler doesn't "compile all the code" is if you are using the CPP extension and #ifdef etc. to exclude some. -- brandon s allbery kf8nh allbery.b at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From frederic-emmanuel.picca at synchrotron-soleil.fr Fri Dec 14 15:26:47 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Fri, 14 Dec 2018 15:26:47 +0000 Subject: [Haskell-cafe] MonadThrow, MonadReader and shake In-Reply-To: References: Message-ID: Hello , I would like your opinion, about this thread. http://mail.haskell.org/pipermail/beginners/2018-December/018403.html I do not know how to solve the issue. thanks Frederic From mattei at oca.eu Fri Dec 14 15:32:03 2018 From: mattei at oca.eu (Damien Mattei) Date: Fri, 14 Dec 2018 16:32:03 +0100 Subject: [Haskell-cafe] (SPAM 3)Re: fmap use In-Reply-To: References: <5C138AC9.50200@oca.eu> <20181214112238.nkoyagudmjxyafu2@weber> <20181214114544.ox7gxgqi5j7dwqjw@weber> <5C13BFD3.1050804@oca.eu> Message-ID: <5C13CCF3.7020600@oca.eu> yes i must admit but things are more and more weirds.... non i do not know why the first of those lines is OK and the other not for compilation: bd_rows <- query conn qry_head (Only (name::String)) bd_rows_WDS <- query conn qry_head_WDS (Only (name::String)) note:if i swap the order it always the line with qry_head_WDS that fails: *Main> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:202:20: error: • Ambiguous type variable ‘r0’ arising from a use of ‘query’ prevents the constraint ‘(QueryResults r0)’ from being solved. Probable fix: use a type annotation to specify what ‘r0’ should be. These potential instances exist: instance Result a => QueryResults (Only a) -- Defined in ‘Database.MySQL.Simple.QueryResults’ instance (Result a, Result b) => QueryResults (a, b) -- Defined in ‘Database.MySQL.Simple.QueryResults’ instance (Result a, Result b, Result c) => QueryResults (a, b, c) -- Defined in ‘Database.MySQL.Simple.QueryResults’ ...plus 21 others (use -fprint-potential-instances to see them all) • In a stmt of a 'do' block: bd_rows_WDS <- query conn qry_head_WDS (Only (name :: String)) In the expression: do conn <- connect defaultConnectInfo {connectHost = "moita", connectUser = "mattei", connectPassword = "sidonie2", connectDatabase = "sidonie"} rows <- query_ conn "SELECT Nom,distance FROM AngularDistance WHERE distance > 0.000278" let lg = Prelude.length rows let tst = ... .... In an equation for ‘main’: main = do conn <- connect defaultConnectInfo {connectHost = "moita", connectUser = "mattei", connectPassword = "sidonie2", connectDatabase = "sidonie"} rows <- query_ conn "SELECT Nom,distance FROM AngularDistance WHERE distance > 0.000278" let lg = ... .... | 202 | bd_rows_WDS <- query conn qry_head_WDS (Only (name::String)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Failed, no modules loaded. for the curious i attach the whole code (UpdateSidonie.hs), i'm really tired of Haskell.... i hope with the file it will be more easy to help me... Le 14/12/2018 16:14, Brandon Allbery a écrit : > On Fri, Dec 14, 2018 at 9:36 AM Damien Mattei > wrote: > > in fact due to lazy evaluation i'm not sure it compiles all the code > because a more simple example give compilation errors: > > > Er? Lazy evaluation has nothing to do with what gets compiled; the only > way the compiler doesn't "compile all the code" is if you are using the > CPP extension and #ifdef etc. to exclude some. > > -- > brandon s allbery kf8nh > allbery.b at gmail.com -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS -------------- next part -------------- A non-text attachment was scrubbed... Name: UpdateSidonie.hs Type: text/x-haskell Size: 8181 bytes Desc: not available URL: From tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk Fri Dec 14 15:42:06 2018 From: tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk (Tom Ellis) Date: Fri, 14 Dec 2018 15:42:06 +0000 Subject: [Haskell-cafe] (SPAM 3)Re: fmap use In-Reply-To: <5C13BFD3.1050804@oca.eu> References: <5C138AC9.50200@oca.eu> <20181214112238.nkoyagudmjxyafu2@weber> <20181214114544.ox7gxgqi5j7dwqjw@weber> <5C13BFD3.1050804@oca.eu> Message-ID: <20181214154206.ay3sorxgxcjhzcba@weber> If you want to print something out use putStrLn. It will work. On Fri, Dec 14, 2018 at 03:36:03PM +0100, Damien Mattei wrote: > so itried you code,surpringly it compiles but when i launch it the > function can not print somethin on screen, i assume it is because > function are pure in haskell, nor with putStrln or Debug.trace: > > getBD_WDS :: Connection -> String -> IO Float > getBD_WDS conn name = do > let qry_head = "select DNUM from WDS where DISC = ?" :: Query > > bd_rows <- query conn qry_head (Only name) > > let lg = Prelude.length bd_rows > > -- putStrLn (if lg > 1 then "some" else "one or zero") > let tst = trace (if lg > 1 then "some" else "one or zero") (if lg > 1 > then "some" else "one or zero") > > -- let noBDtxt :: Text > let noBDtxt = fromOnly (Prelude.head bd_rows) > > -- noBDstr :: String > let noBDstr = Text.unpack noBDtxt > > -- noBDfp :: Float > let noBDfp = read noBDstr > > return noBDfp From whosekiteneverfly at gmail.com Sat Dec 15 09:42:06 2018 From: whosekiteneverfly at gmail.com (Yuji Yamamoto) Date: Sat, 15 Dec 2018 18:42:06 +0900 Subject: [Haskell-cafe] Upload new version of indexed-extras or let me take over Message-ID: Hello, this is a reminder of the message I sent (only to Reiner) about three weeks ago. I'm developing some libraries in Haskell with your package indexed-extras . I found the package can't be built with the latest bifunctor package due to its version constraint. I sent a pull request to fix the problem and it has already been merged. Can you release the new version on Hackage? It's now the biggest obstacle developing my libraries depending on it. If you can't maintain the package anymore, I'm willing to take over. Thanks in advance. -- 山本悠滋 twitter: @igrep GitHub: https://github.com/igrep GitLab: https://gitlab.com/igrep Facebook: http://www.facebook.com/igrep -------------- next part -------------- An HTML attachment was scrubbed... URL: From will.yager at gmail.com Sat Dec 15 12:58:33 2018 From: will.yager at gmail.com (William Yager) Date: Sat, 15 Dec 2018 20:58:33 +0800 Subject: [Haskell-cafe] How to unify these three types with identical structures into one definition? In-Reply-To: <8c8e939b-521f-abbd-4a1d-32e2c4a71b5f@gmail.com> References: <28219dbc.af97.167acca2714.Coremail.ducis_cn@126.com> <8c8e939b-521f-abbd-4a1d-32e2c4a71b5f@gmail.com> Message-ID: There may be some fun to be had with QuantifiedConstraints. I've thought about solving similar parser/formatter problems this way, extending parsers via functor composition. Consider: > data F f = F (f (F f)) > -- Sadly the below does not work. It seems like maybe it should be able to work? > instance (forall a . Show a => Show (f a)) => Show (F f) where show (F f) = "(F " ++ show f ++ ")" :23:10: error: • The constraint ‘Show (f a)’ is no smaller than the instance head ‘Show (F f)’ (Use UndecidableInstances to permit this) • In the instance declaration for ‘Show (F f)’ > -- We can get something almost as good > class (forall a . Show a => Show (f a)) => Show1 f > instance Show1 f => Show (F f) where show (F f) = "(F " ++ show f ++ ")" > instance Show1 Maybe > show (F $ Just $ F $ Nothing) "(F Just (F Nothing))" On Fri, Dec 14, 2018 at 10:52 PM MarLinn wrote: > Hi Ducis, > > you can parametrise over type variables of other kinds than just *. > > If what you write is really what you want, the most straightforward answer > is simply > > data ExprG f > = Var VarName > | Enclosed VarName (f Expr) VarName > | Prefix (f Expr) (f Expr) > | Ternary (f Expr) VarName (f Expr) VarName (f Expr) > > type Expr = ExprG Identity -- From Data.Functor.Identity > type ExprL = ExprG [] > type ExprD = ExprG DList > > There is no mention of the word "functor" because you will have to add > that constraint to the usage sites. > > Downside: notice that the deriving clauses are gone because the instances > aren't as easy to derive any more. Even the simplest and most harmless way > I know to get that possibility back involves two language extensions: > StandaloneDeriving and FlexibleInstances. With those you can write > > deriving instance Show (ExprG Identity) > deriving instance Show (ExprG []) > deriving instance Show (ExprG DList) > deriving instance Eq (ExprG Identity) > : > > I suspect though that what you actually want, but didn't write, is more > along the lines of > > data ExprL = … | EnclosedL VarName [ExprL] VarName | … -- using ExprL instead of Expr on the right side > > data ExprD = … | EnclosedD VarName (DList ExprD) VarName | … -- using ExprD instead of Expr on the right side > > The good news is that if you have the first solution, this step is rather > simple. Because you can just use replace Expr with ExprG f again: > > data ExprG f > = Var VarName > | Enclosed VarName (f (ExprG f)) VarName > | Prefix (f (ExprG f)) (f (ExprG f)) > | Ternary (f (ExprG f)) VarName (f (ExprG f)) VarName (f (ExprG f)) > > The better news is that although this looks repetitive and hard to read, > it's well on the way to discovering the magic of the Free Monad. > > Hope this helps. > > Cheers, > MarLinn > > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From will.yager at gmail.com Sun Dec 16 06:00:39 2018 From: will.yager at gmail.com (William Yager) Date: Sun, 16 Dec 2018 14:00:39 +0800 Subject: [Haskell-cafe] How to unify these three types with identical structures into one definition? In-Reply-To: References: <28219dbc.af97.167acca2714.Coremail.ducis_cn@126.com> <8c8e939b-521f-abbd-4a1d-32e2c4a71b5f@gmail.com> Message-ID: I've been thinking about this a bit more - I'm still not sure if it's correct for the instance above to require UndecidableInstances. Why is the `a` counting towards the "size" of the constraint? It seems like since it's introduced existentially, it shouldn't introduce ambiguities in the typeclass resolution mechanism. However, I know little about the internals of the typeclass solver, so I could be wrong about that. On Sat, Dec 15, 2018 at 8:58 PM William Yager wrote: > There may be some fun to be had with QuantifiedConstraints. I've thought > about solving similar parser/formatter problems this way, extending parsers > via functor composition. Consider: > > > data F f = F (f (F f)) > > > -- Sadly the below does not work. It seems like maybe it should be able > to work? > > > instance (forall a . Show a => Show (f a)) => Show (F f) where show (F > f) = "(F " ++ show f ++ ")" > > > :23:10: error: > > • The constraint ‘Show (f a)’ > > is no smaller than the instance head ‘Show (F f)’ > > (Use UndecidableInstances to permit this) > > • In the instance declaration for ‘Show (F f)’ > > > -- We can get something almost as good > > > class (forall a . Show a => Show (f a)) => Show1 f > > > instance Show1 f => Show (F f) where show (F f) = "(F " ++ show f ++ ")" > > > instance Show1 Maybe > > > show (F $ Just $ F $ Nothing) > > "(F Just (F Nothing))" > > > > On Fri, Dec 14, 2018 at 10:52 PM MarLinn wrote: > >> Hi Ducis, >> >> you can parametrise over type variables of other kinds than just *. >> >> If what you write is really what you want, the most straightforward >> answer is simply >> >> data ExprG f >> = Var VarName >> | Enclosed VarName (f Expr) VarName >> | Prefix (f Expr) (f Expr) >> | Ternary (f Expr) VarName (f Expr) VarName (f Expr) >> >> type Expr = ExprG Identity -- From Data.Functor.Identity >> type ExprL = ExprG [] >> type ExprD = ExprG DList >> >> There is no mention of the word "functor" because you will have to add >> that constraint to the usage sites. >> >> Downside: notice that the deriving clauses are gone because the instances >> aren't as easy to derive any more. Even the simplest and most harmless way >> I know to get that possibility back involves two language extensions: >> StandaloneDeriving and FlexibleInstances. With those you can write >> >> deriving instance Show (ExprG Identity) >> deriving instance Show (ExprG []) >> deriving instance Show (ExprG DList) >> deriving instance Eq (ExprG Identity) >> : >> >> I suspect though that what you actually want, but didn't write, is more >> along the lines of >> >> data ExprL = … | EnclosedL VarName [ExprL] VarName | … -- using ExprL instead of Expr on the right side >> >> data ExprD = … | EnclosedD VarName (DList ExprD) VarName | … -- using ExprD instead of Expr on the right side >> >> The good news is that if you have the first solution, this step is rather >> simple. Because you can just use replace Expr with ExprG f again: >> >> data ExprG f >> = Var VarName >> | Enclosed VarName (f (ExprG f)) VarName >> | Prefix (f (ExprG f)) (f (ExprG f)) >> | Ternary (f (ExprG f)) VarName (f (ExprG f)) VarName (f (ExprG f)) >> >> The better news is that although this looks repetitive and hard to read, >> it's well on the way to discovering the magic of the Free Monad. >> >> Hope this helps. >> >> Cheers, >> MarLinn >> >> >> _______________________________________________ >> Haskell-Cafe mailing list >> To (un)subscribe, modify options or view archives go to: >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> Only members subscribed via the mailman list are allowed to post. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattei at oca.eu Tue Dec 18 10:16:19 2018 From: mattei at oca.eu (Damien Mattei) Date: Tue, 18 Dec 2018 11:16:19 +0100 Subject: [Haskell-cafe] handling NULL value in database query with Maybe (or other ...) Message-ID: <5C18C8F3.5080708@oca.eu> Hi, i have this query in SQL used by my Haskell code: let name = "A 20" -- return the list of N°BD from WDS for a given name let qry_head_WDS = "select DNUM from WDS where DISC = ?" :: Query putStrLn "before query WDS" bd_rows_WDS <- query conn qry_head_WDS (Only (name::String)) putStrLn "after query WDS" forM_ bd_rows_WDS $ \(Only a) -> putStrLn $ Text.unpack a works well if there is no NULL values in a database, but if NULL value for field N°BD i got this exception at runtime: before query WDS *** Exception: UnexpectedNull {errSQLType = "String", errHaskellType = "Text", errFieldName = "DNUM", errMessage = "unexpected null in table WDS of database sidonie"} *Main> i need some code ,perheaps uing Maybe to handle the NULL value in the field N°BD i think Haskell have special feature to program this , i read the article: https://lukeplant.me.uk/blog/posts/null-pointers-vs-none-vs-maybe/ but for now i have no concrete solution.... Regards, Damien -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From aquagnu at gmail.com Tue Dec 18 10:59:57 2018 From: aquagnu at gmail.com (Paul) Date: Tue, 18 Dec 2018 12:59:57 +0200 Subject: [Haskell-cafe] handling NULL value in database query with Maybe (or other ...) In-Reply-To: <5C18C8F3.5080708@oca.eu> References: <5C18C8F3.5080708@oca.eu> Message-ID: <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> If you use Database.Sqlite.Simple library you need to declare returning type as "Maybe XYZ" mandatory., so type will be Only (Maybe String). When I forget about Maybe, I get then same error as you. 18.12.2018 12:16, Damien Mattei wrote: > Hi, > > i have this query in SQL used by my Haskell code: > > let name = "A 20" > > -- return the list of N°BD from WDS for a given name > let qry_head_WDS = "select DNUM from WDS where DISC = ?" :: Query > putStrLn "before query WDS" > bd_rows_WDS <- query conn qry_head_WDS (Only (name::String)) > putStrLn "after query WDS" > > forM_ bd_rows_WDS $ \(Only a) -> > putStrLn $ Text.unpack a > > works well if there is no NULL values in a database, but if NULL value > for field N°BD i got this exception at runtime: > > before query WDS > *** Exception: UnexpectedNull {errSQLType = "String", errHaskellType = > "Text", errFieldName = "DNUM", errMessage = "unexpected null in table > WDS of database sidonie"} > *Main> > > i need some code ,perheaps uing Maybe to handle the NULL value in the > field N°BD > > i think Haskell have special feature to program this , i read the article: > https://lukeplant.me.uk/blog/posts/null-pointers-vs-none-vs-maybe/ > > but for now i have no concrete solution.... > > Regards, > Damien > From mattei at oca.eu Tue Dec 18 11:11:33 2018 From: mattei at oca.eu (Damien Mattei) Date: Tue, 18 Dec 2018 12:11:33 +0100 Subject: [Haskell-cafe] handling NULL value in database query with Maybe (or other ...) In-Reply-To: <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> Message-ID: <5C18D5E5.8090703@oca.eu> unfortunately no i'm using Database.MySQL.Simple and the doc mention also: Handling null values The type of a result tuple will look something like this: (Text, Int, Int) Although SQL can accommodate NULL as a value for any of these types, Haskell cannot. If your result contains columns that may be NULL, be sure that you use Maybe in those positions of of your tuple. (Text, Maybe Int, Int) If query encounters a NULL in a row where the corresponding Haskell type is not Maybe, it will throw a ResultError exception. but when i put Maybe in my code like this: forM_ bd_rows_WDS $ \(Maybe a) -> putStrLn $ Text.unpack a i have this error at compilation: *Main> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:255:27: error: Not in scope: data constructor ‘Maybe’ Perhaps you meant variable ‘maybe’ (imported from Data.Maybe) | 255 | forM_ bd_rows_WDS $ \(Maybe a) -> | ^^^^^ Failed, no modules loaded. Le 18/12/2018 11:59, Paul a écrit : > If you use Database.Sqlite.Simple library you need to declare returning > type as "Maybe XYZ" mandatory., so type will be > > Only (Maybe String). When I forget about Maybe, I get then same error as > you. > > > 18.12.2018 12:16, Damien Mattei wrote: >> Hi, >> >> i have this query in SQL used by my Haskell code: >> >> let name = "A 20" >> >> -- return the list of N°BD from WDS for a given name >> let qry_head_WDS = "select DNUM from WDS where DISC = ?" :: Query >> putStrLn "before query WDS" >> bd_rows_WDS <- query conn qry_head_WDS (Only (name::String)) >> putStrLn "after query WDS" >> >> forM_ bd_rows_WDS $ \(Only a) -> >> putStrLn $ Text.unpack a >> >> works well if there is no NULL values in a database, but if NULL value >> for field N°BD i got this exception at runtime: >> >> before query WDS >> *** Exception: UnexpectedNull {errSQLType = "String", errHaskellType = >> "Text", errFieldName = "DNUM", errMessage = "unexpected null in table >> WDS of database sidonie"} >> *Main> >> >> i need some code ,perheaps uing Maybe to handle the NULL value in the >> field N°BD >> >> i think Haskell have special feature to program this , i read the >> article: >> https://lukeplant.me.uk/blog/posts/null-pointers-vs-none-vs-maybe/ >> >> but for now i have no concrete solution.... >> >> Regards, >> Damien >> > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From mattei at oca.eu Tue Dec 18 11:14:13 2018 From: mattei at oca.eu (Damien Mattei) Date: Tue, 18 Dec 2018 12:14:13 +0100 Subject: [Haskell-cafe] handling NULL value in database query with Maybe (or other ...) In-Reply-To: <5C18D5E5.8090703@oca.eu> References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> Message-ID: <5C18D685.1020200@oca.eu> the URL of the doc i quoted is : http://hackage.haskell.org/package/mysql-simple-0.4.5/docs/Database-MySQL-Simple.html unfortunately there is no developped example to help me Le 18/12/2018 12:11, Damien Mattei a écrit : > unfortunately no i'm using Database.MySQL.Simple > and the doc mention also: > > Handling null values > > The type of a result tuple will look something like this: > > (Text, Int, Int) > > Although SQL can accommodate NULL as a value for any of these types, > Haskell cannot. If your result contains columns that may be NULL, be > sure that you use Maybe in those positions of of your tuple. > > (Text, Maybe Int, Int) > > If query encounters a NULL in a row where the corresponding Haskell type > is not Maybe, it will throw a ResultError exception. > > but when i put Maybe in my code like this: > > forM_ bd_rows_WDS $ \(Maybe a) -> > putStrLn $ Text.unpack a > > i have this error at compilation: > > *Main> :load UpdateSidonie > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > UpdateSidonie.hs:255:27: error: > Not in scope: data constructor ‘Maybe’ > Perhaps you meant variable ‘maybe’ (imported from Data.Maybe) > | > 255 | forM_ bd_rows_WDS $ \(Maybe a) -> > | ^^^^^ > Failed, no modules loaded. > > > Le 18/12/2018 11:59, Paul a écrit : >> If you use Database.Sqlite.Simple library you need to declare returning >> type as "Maybe XYZ" mandatory., so type will be >> >> Only (Maybe String). When I forget about Maybe, I get then same error as >> you. >> >> >> 18.12.2018 12:16, Damien Mattei wrote: >>> Hi, >>> >>> i have this query in SQL used by my Haskell code: >>> >>> let name = "A 20" >>> >>> -- return the list of N°BD from WDS for a given name >>> let qry_head_WDS = "select DNUM from WDS where DISC = ?" :: Query >>> putStrLn "before query WDS" >>> bd_rows_WDS <- query conn qry_head_WDS (Only (name::String)) >>> putStrLn "after query WDS" >>> >>> forM_ bd_rows_WDS $ \(Only a) -> >>> putStrLn $ Text.unpack a >>> >>> works well if there is no NULL values in a database, but if NULL value >>> for field N°BD i got this exception at runtime: >>> >>> before query WDS >>> *** Exception: UnexpectedNull {errSQLType = "String", errHaskellType = >>> "Text", errFieldName = "DNUM", errMessage = "unexpected null in table >>> WDS of database sidonie"} >>> *Main> >>> >>> i need some code ,perheaps uing Maybe to handle the NULL value in the >>> field N°BD >>> >>> i think Haskell have special feature to program this , i read the >>> article: >>> https://lukeplant.me.uk/blog/posts/null-pointers-vs-none-vs-maybe/ >>> >>> but for now i have no concrete solution.... >>> >>> Regards, >>> Damien >>> >> >> _______________________________________________ >> Haskell-Cafe mailing list >> To (un)subscribe, modify options or view archives go to: >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> Only members subscribed via the mailman list are allowed to post. > -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From tom at stejskal.me Tue Dec 18 12:34:11 2018 From: tom at stejskal.me (tom.stejskal) Date: Tue, 18 Dec 2018 12:34:11 +0000 Subject: [Haskell-cafe] handling NULL value in database query with Maybe (or other ...) In-Reply-To: <5C18D5E5.8090703@oca.eu> References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> Message-ID: Hi Damien, the problem is that you are trying to use a type (Maybe), but you should use a data constructor (in this case Just or Nothing) in the pattern match (see the error message). Something like: forM_ bd_rows_WDS $ \x -> case x of Nothing -> putStrLn "NULL" Just y -> putStrLn $ Text.unpack y Regards, Tom Sent with ProtonMail Secure Email. ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Tuesday, December 18, 2018 12:11 PM, Damien Mattei wrote: > unfortunately no i'm using Database.MySQL.Simple > and the doc mention also: > > Handling null values > > The type of a result tuple will look something like this: > > (Text, Int, Int) > > Although SQL can accommodate NULL as a value for any of these types, > Haskell cannot. If your result contains columns that may be NULL, be > sure that you use Maybe in those positions of of your tuple. > > (Text, Maybe Int, Int) > > If query encounters a NULL in a row where the corresponding Haskell type > is not Maybe, it will throw a ResultError exception. > > but when i put Maybe in my code like this: > > forM_ bd_rows_WDS $ \(Maybe a) -> > > putStrLn $ Text.unpack a > > > i have this error at compilation: > > *Main> :load UpdateSidonie > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > UpdateSidonie.hs:255:27: error: > Not in scope: data constructor ‘Maybe’ > Perhaps you meant variable ‘maybe’ (imported from Data.Maybe) > | > 255 | forM_ bd_rows_WDS $ \(Maybe a) -> > > | ^^^^^ > > > Failed, no modules loaded. > > Le 18/12/2018 11:59, Paul a écrit : > > > If you use Database.Sqlite.Simple library you need to declare returning > > type as "Maybe XYZ" mandatory., so type will be > > Only (Maybe String). When I forget about Maybe, I get then same error as > > you. > > 18.12.2018 12:16, Damien Mattei wrote: > > > > > Hi, > > > i have this query in SQL used by my Haskell code: > > > > > > let name = "A 20" > > > > > > > > > -- return the list of N°BD from WDS for a given name > > > let qry_head_WDS = "select DNUM from WDS where DISC = ?" :: Query > > > putStrLn "before query WDS" > > > bd_rows_WDS <- query conn qry_head_WDS (Only (name::String)) > > > putStrLn "after query WDS" > > > > > > forM_ bd_rows_WDS $ \\(Only a) -> > > > putStrLn $ Text.unpack a > > > > > > > > > works well if there is no NULL values in a database, but if NULL value > > > for field N°BD i got this exception at runtime: > > > before query WDS > > > *** Exception: UnexpectedNull {errSQLType = "String", errHaskellType = > > > "Text", errFieldName = "DNUM", errMessage = "unexpected null in table > > > WDS of database sidonie"} > > > *Main> > > > i need some code ,perheaps uing Maybe to handle the NULL value in the > > > field N°BD > > > i think Haskell have special feature to program this , i read the > > > article: > > > https://lukeplant.me.uk/blog/posts/null-pointers-vs-none-vs-maybe/ > > > but for now i have no concrete solution.... > > > Regards, > > > Damien > > > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > > -- > > Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS > > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. From mattei at oca.eu Tue Dec 18 14:43:35 2018 From: mattei at oca.eu (Damien Mattei) Date: Tue, 18 Dec 2018 15:43:35 +0100 Subject: [Haskell-cafe] handling NULL value in database query with Maybe (or other ...) In-Reply-To: References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> Message-ID: <5C190797.3080701@oca.eu> thank you Tom, it is the kind of answer that help me i insert this and it is ok now: forM_ bd_rows_WDS $ \(Only x) -> case x of Nothing -> putStrLn ("x =" ++ "NULL") Just x -> putStrLn $ ("x =" ++ Text.unpack x) i had seen a such solution on web but thought the Maybe was the solution, i hoped asked could avoid using sort of Null pointer as mentioned in this article: https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/ if someone else have a simpler solution email me Le 18/12/2018 13:34, tom.stejskal a écrit : > case x of > Nothing -> putStrLn "NULL" > Just y -> putStrLn $ Text.unpack y -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk Tue Dec 18 15:16:39 2018 From: tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk (Tom Ellis) Date: Tue, 18 Dec 2018 15:16:39 +0000 Subject: [Haskell-cafe] handling NULL value in database query with Maybe (or other ...) In-Reply-To: <5C190797.3080701@oca.eu> References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> Message-ID: <20181218151639.jv3j3rkmgwhxdk4e@weber> That is using Maybe and is not a null pointer! Just and Nothing are the constructors of Maybe. On Tue, Dec 18, 2018 at 03:43:35PM +0100, Damien Mattei wrote: > thank you Tom, it is the kind of answer that help me > i insert this and it is ok now: > forM_ bd_rows_WDS $ \(Only x) -> > case x of > Nothing -> putStrLn ("x =" ++ "NULL") > Just x -> putStrLn $ ("x =" ++ Text.unpack x) > i had seen a such solution on web but thought the Maybe was the > solution, i hoped asked could avoid using sort of Null pointer as > mentioned in this article: > https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/ > if someone else have a simpler solution email me > > > Le 18/12/2018 13:34, tom.stejskal a écrit : > > case x of > > Nothing -> putStrLn "NULL" > > Just y -> putStrLn $ Text.unpack y From neil_mayhew at users.sourceforge.net Tue Dec 18 15:22:44 2018 From: neil_mayhew at users.sourceforge.net (Neil Mayhew) Date: Tue, 18 Dec 2018 08:22:44 -0700 Subject: [Haskell-cafe] handling NULL value in database query with Maybe (or other ...) In-Reply-To: <5C190797.3080701@oca.eu> References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> Message-ID: On 2018-12-18 7:43 AM, Damien Mattei wrote: > i hoped asked could avoid using sort of Null pointer as mentioned in > this article: > https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/ > if someone else have a simpler solution email me You can avoid it: make the DNUM column non-NULL in your database schema. That "worst mistake" applies to databases as well as programming languages! :-) If you have to allow NULL in the database, then you have to handle Nothing in your code. However, a neater way of doing it is to use the maybe function: forM_ bd_rows_WDS $ \(Only x) -> putStrLn $ "x =" ++ maybe "" Text.unpack x This allows you to provide a default value in your code for when the column is NULL. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattei at oca.eu Tue Dec 18 15:34:15 2018 From: mattei at oca.eu (Damien Mattei) Date: Tue, 18 Dec 2018 16:34:15 +0100 Subject: [Haskell-cafe] (SPAM 3)Re: handling NULL value in database query with Maybe (or other ...) In-Reply-To: <20181218151639.jv3j3rkmgwhxdk4e@weber> References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> <20181218151639.jv3j3rkmgwhxdk4e@weber> Message-ID: <5C191377.3040602@oca.eu> ok well i do not want to open a discussion here, but i do not see any benefit in Haskell using Nothing and Just compared to other language, it's the same than if i had written in C something like : if (x == NULL) printf("NULL\n"); else printf("%s",*x); i expected more from Haskell... ok reading twice the article in link, i admit there should be some adavantage using Nothing instead of null, such as type, and genericity and not being spcecific to alloated memory as in C ... Le 18/12/2018 16:16, Tom Ellis a écrit : > That is using Maybe and is not a null pointer! > > Just and Nothing are the constructors of Maybe. > > On Tue, Dec 18, 2018 at 03:43:35PM +0100, Damien Mattei wrote: >> thank you Tom, it is the kind of answer that help me >> i insert this and it is ok now: >> forM_ bd_rows_WDS $ \(Only x) -> >> case x of >> Nothing -> putStrLn ("x =" ++ "NULL") >> Just x -> putStrLn $ ("x =" ++ Text.unpack x) >> i had seen a such solution on web but thought the Maybe was the >> solution, i hoped asked could avoid using sort of Null pointer as >> mentioned in this article: >> https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/ >> if someone else have a simpler solution email me >> >> >> Le 18/12/2018 13:34, tom.stejskal a écrit : >>> case x of >>> Nothing -> putStrLn "NULL" >>> Just y -> putStrLn $ Text.unpack y > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. > -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From mattei at oca.eu Tue Dec 18 15:44:09 2018 From: mattei at oca.eu (Damien Mattei) Date: Tue, 18 Dec 2018 16:44:09 +0100 Subject: [Haskell-cafe] handling NULL value in database query with Maybe (or other ...) In-Reply-To: References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> Message-ID: <5C1915C9.6040205@oca.eu> cool... forM_ bd_rows_WDS $ \(Only x) -> putStrLn $ "x =" ++ maybe "NULL" Text.unpack x it worked... thank you , i will which on i use because i need to forget all NULL values ,get just an answer strange lazy evaluation at runtime i had error at this: putStrLn "before query WDS" bd_rows_WDS <- query conn qry_head_WDS (Only (name::String)) putStrLn "after query WDS" and it has been solved 20 lines below withe maybe: forM_ bd_rows_WDS $ \(Only x) -> putStrLn $ "x =" ++ maybe "NULL" Text.unpack x that now deal with NULL values i suppose it's because until some printing is done nothing is evaluated before in lazy programming... Le 18/12/2018 16:22, Neil Mayhew a écrit : > On 2018-12-18 7:43 AM, Damien Mattei wrote: >> i hoped asked could avoid using sort of Null pointer as mentioned in >> this article: >> https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/ >> if someone else have a simpler solution email me > > You can avoid it: make the DNUM column non-NULL in your database schema. > That "worst mistake" applies to databases as well as programming > languages! :-) > > If you have to allow NULL in the database, then you have to handle > Nothing in your code. However, a neater way of doing it is to use the > maybe function: > > forM_ bd_rows_WDS $ \(Only x) -> > putStrLn $ "x =" ++ maybe "" Text.unpack x > > > This allows you to provide a default value in your code for when the > column is NULL. > > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. > -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From allbery.b at gmail.com Tue Dec 18 15:58:00 2018 From: allbery.b at gmail.com (Brandon Allbery) Date: Tue, 18 Dec 2018 10:58:00 -0500 Subject: [Haskell-cafe] (SPAM 3)Re: handling NULL value in database query with Maybe (or other ...) In-Reply-To: <5C191377.3040602@oca.eu> References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> <20181218151639.jv3j3rkmgwhxdk4e@weber> <5C191377.3040602@oca.eu> Message-ID: You seem rather confused about the topic. What magic were you expecting to happen if something doesn't have a value? The point of Maybe is it lets you (a) specify exactly where things can lack a value (as, for example, when a database column can produce a NULL instead of a value), and (b) explicitly handle those instead of hoping the program somehow reads your mind to figure out how to deal with it or feeds you some unexpected 'nil' or whatever. Consider in this case that the database does not care if a column doesn't happen to have any NULLs, it cares only that the column was not declared NOT NULL and therefore *can* contain a NULL. Which is the same condition where you use a Maybe someType in Haskell instead of simply someType. In particular, if you were expecting a database NULL to turn into the empty string or "NULL" or some other such in-band value, how were you expecting to distinguish the case where the database row actually contains that string? That's why databases have NULL to begin with: "no value" distinct from any possible actual value. If you do not want this, declare the column NOT NULL in the database, don't expect the client program to do magic for you. On Tue, Dec 18, 2018 at 10:34 AM Damien Mattei wrote: > ok well i do not want to open a discussion here, but i do not see any > benefit in Haskell using Nothing and Just compared to other language, > it's the same than if i had written in C something like : > if (x == NULL) > printf("NULL\n"); > else > printf("%s",*x); > > i expected more from Haskell... > > ok reading twice the article in link, i admit there should be some > adavantage using Nothing instead of null, such as type, and genericity > and not being spcecific to alloated memory as in C ... > > Le 18/12/2018 16:16, Tom Ellis a écrit : > > That is using Maybe and is not a null pointer! > > > > Just and Nothing are the constructors of Maybe. > > > > On Tue, Dec 18, 2018 at 03:43:35PM +0100, Damien Mattei wrote: > >> thank you Tom, it is the kind of answer that help me > >> i insert this and it is ok now: > >> forM_ bd_rows_WDS $ \(Only x) -> > >> case x of > >> Nothing -> putStrLn ("x =" ++ "NULL") > >> Just x -> putStrLn $ ("x =" ++ Text.unpack x) > >> i had seen a such solution on web but thought the Maybe was the > >> solution, i hoped asked could avoid using sort of Null pointer as > >> mentioned in this article: > >> > https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/ > >> if someone else have a simpler solution email me > >> > >> > >> Le 18/12/2018 13:34, tom.stejskal a écrit : > >>> case x of > >>> Nothing -> putStrLn "NULL" > >>> Just y -> putStrLn $ Text.unpack y > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > > > > -- > Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -- brandon s allbery kf8nh allbery.b at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From vanessa.mchale at iohk.io Tue Dec 18 16:39:12 2018 From: vanessa.mchale at iohk.io (Vanessa McHale) Date: Tue, 18 Dec 2018 10:39:12 -0600 Subject: [Haskell-cafe] Diagnosing build problems when cross-compiling hslua Message-ID: Hi all, I recently ran into some troubles cross-compiling hslua for Raspberry Pi, viz. |cabal new-build --with-ghc arm-linux-gnueabihf-ghc --with-ghc-pkg arm-linux-gnueabihf-ghc-pkg Build profile: -w ghc-8.6.3 -O1 In order, the following will be built (use -v for more details): - hslua-1.0.1 (lib) (configuration changed) Configuring library for hslua-1.0.1.. Preprocessing library for hslua-1.0.1.. Types.hsc: In function ‘_hsc2hs_test1’: Types.hsc:59:12: error: ‘LUA_INTEGER’ undeclared (first use in this function) Types.hsc:59:12: note: each undeclared identifier is reported only once for each function it appears in Types.hsc:59:24: error: expected ‘;’ before numeric constant compilation failed| Any hints as to what's failing? Is this something wrong with hslua, hsc2hs, or cabal? And how would I go about fixing it? Cheers, Vanessa McHale -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From ian at zenhack.net Tue Dec 18 18:59:15 2018 From: ian at zenhack.net (Ian Denhardt) Date: Tue, 18 Dec 2018 13:59:15 -0500 Subject: [Haskell-cafe] (SPAM 3)Re: handling NULL value in database query with Maybe (or other ...) In-Reply-To: <5C191377.3040602@oca.eu> References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> <20181218151639.jv3j3rkmgwhxdk4e@weber> <5C191377.3040602@oca.eu> Message-ID: <154515955524.6293.635784808012290680@localhost.localdomain> Quoting Damien Mattei (2018-12-18 10:34:15) > if (x == NULL) > printf("NULL\n"); > else > printf("%s",*x); C will also allow you to just write: printf("%s", *x); Without the if, which will silently compile without complaint, and then segfault (at best) or corrupt memory at runtime. With Maybe there's no way to try to access the value if it isn't actually there. As others have pointed out, your database has a concept of null (to which the article's complaints are spot on), so somehow you have to model the fact that it may not actually return a string. There are more ergonomic ways of dealing with it than having the same case expression everywhere; other replies suggested using the `maybe` function to supply a default, or modifying the database schema to say NOT NULL -- but you have to deal with it somehow. The advantage of Maybe is: * It makes the possibility of no-value explicit, and not something you can forget to handle. * It makes it possible to express that no-value is *not* a possibility, when that is the case (by just not using a Maybe). -Ian From mike at barrucadu.co.uk Tue Dec 18 19:06:34 2018 From: mike at barrucadu.co.uk (Michael Walker) Date: Tue, 18 Dec 2018 19:06:34 +0000 Subject: [Haskell-cafe] (SPAM 3)Re: handling NULL value in database query with Maybe (or other ...) In-Reply-To: <5C191377.3040602@oca.eu> References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> <20181218151639.jv3j3rkmgwhxdk4e@weber> <5C191377.3040602@oca.eu> Message-ID: On Tue, 18 Dec 2018 at 15:34, Damien Mattei wrote: > > ok well i do not want to open a discussion here, but i do not see any > benefit in Haskell using Nothing and Just compared to other language, > it's the same than if i had written in C something like : > if (x == NULL) > printf("NULL\n"); > else > printf("%s",*x); > > i expected more from Haskell... Well, you have to remember to do that in C, but in Haskell the compiler won't let you use a "Maybe a" as an "a". They're totally different things. That seems a pretty huge benefit to me, even ignoring everything else. What more could you want? -- Michael Walker (http://www.barrucadu.co.uk) From aquagnu at gmail.com Tue Dec 18 19:28:53 2018 From: aquagnu at gmail.com (Paul) Date: Tue, 18 Dec 2018 21:28:53 +0200 Subject: [Haskell-cafe] (SPAM 3)Re: handling NULL value in database querywith Maybe (or other ...) In-Reply-To: <154515955524.6293.635784808012290680@localhost.localdomain> References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> <20181218151639.jv3j3rkmgwhxdk4e@weber> <5C191377.3040602@oca.eu> <154515955524.6293.635784808012290680@localhost.localdomain> Message-ID: <5c194a71.1c69fb81.2db4b.c7ab@mx.google.com> ➢ The advantage of Maybe is... This is not advantage of Maybe, but advantage of pattern-matching which allows you to “extract” value only from “Just a” branch and no way to get value from Nothing. But wait, I can get the same exception as in C/C++: fromJust Nothing without “if isJust...”! So, Damien is right here – no difference with C and Haskell is not more safe than C here – and you CAN omit checking and to get run time exception. I’m not sure about SML, may be it does not allow to get value in so dangerous way, but Haskell allows, like C. You will not get warning at compile time even 😊 But in C# 8 you will get warning with such dangerous using of Nullable. Common rule is to use pattern-matching. The same technique, sure, is possible in C – you need to wrap value in some structure and to use special functions/macros to extract value, modern C++ libraries already have “option” types. From: Ian Denhardt Sent: 18 декабря 2018 г. 21:01 To: Damien Mattei; haskell-cafe at haskell.org Subject: Re: [Haskell-cafe] (SPAM 3)Re: handling NULL value in database querywith Maybe (or other ...) Quoting Damien Mattei (2018-12-18 10:34:15) > if (x == NULL) > printf("NULL\n"); > else > printf("%s",*x); C will also allow you to just write: printf("%s", *x); Without the if, which will silently compile without complaint, and then segfault (at best) or corrupt memory at runtime. With Maybe there's no way to try to access the value if it isn't actually there. As others have pointed out, your database has a concept of null (to which the article's complaints are spot on), so somehow you have to model the fact that it may not actually return a string. There are more ergonomic ways of dealing with it than having the same case expression everywhere; other replies suggested using the `maybe` function to supply a default, or modifying the database schema to say NOT NULL -- but you have to deal with it somehow. The advantage of Maybe is: * It makes the possibility of no-value explicit, and not something you can forget to handle. * It makes it possible to express that no-value is *not* a possibility, when that is the case (by just not using a Maybe). -Ian _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian at zenhack.net Tue Dec 18 19:56:08 2018 From: ian at zenhack.net (Ian Denhardt) Date: Tue, 18 Dec 2018 14:56:08 -0500 Subject: [Haskell-cafe] (SPAM 3)Re: handling NULL value in database querywith Maybe (or other ...) In-Reply-To: <5c194a71.1c69fb81.2db4b.c7ab@mx.google.com> References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> <20181218151639.jv3j3rkmgwhxdk4e@weber> <5C191377.3040602@oca.eu> <154515955524.6293.635784808012290680@localhost.localdomain> <5c194a71.1c69fb81.2db4b.c7ab@mx.google.com> Message-ID: <154516296854.8140.14484476994553077584@localhost.localdomain> Quoting Paul (2018-12-18 14:28:53) > But wait, I can get the same exception as in C/C++: fromJust Nothing > without "if isJust..."! So, Damien is right here - no difference with > C and Haskell is not more safe than C here - and you CAN omit checking > and to get run time exception. First, C doesn't give you an exception, it just tramples over memory. The OS jumps through hoops to make it likely that it will start with memory that will cause it to be killed before it does any real damage, but it's still a different beast. But if you really want that behavior could also just do: case x of Just x -> x Nothing -> unsafeCoerce 0 ..and pattern matching doesn't save you. So yes, if you heap on enough pedantry, you can claim that Haskell is not safer than C. But this argument is divorced from the reality of what writing code is actually like in these two languages. Segfaults and memory corruption are the norm in C, and not in Haskell. > C# 8 > > [...] > > modern C++ I did say C, not C# or C++ which are entirely different languages. Type-level nil tracking actually does give you the benefits I describe, though it's not as nice as proper sum types more generally. I did not say that Haskell's Maybe is the only way to achieve this. -Ian From mattei at oca.eu Wed Dec 19 08:33:42 2018 From: mattei at oca.eu (Damien Mattei) Date: Wed, 19 Dec 2018 09:33:42 +0100 Subject: [Haskell-cafe] handling NULL value in database query with Maybe (or other ...) In-Reply-To: References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> Message-ID: <5C1A0266.7030006@oca.eu> Le 18/12/2018 16:22, Neil Mayhew a écrit : > On 2018-12-18 7:43 AM, Damien Mattei wrote: >> i hoped asked could avoid using sort of Null pointer as mentioned in >> this article: >> https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/ >> if someone else have a simpler solution email me > > You can avoid it: make the DNUM column non-NULL in your database schema. > That "worst mistake" applies to databases as well as programming > languages! :-) yes :-) but it is not me that create the database,it's a 20 years old database.... > > If you have to allow NULL in the database, then you have to handle > Nothing in your code. However, a neater way of doing it is to use the > maybe function: > > forM_ bd_rows_WDS $ \(Only x) -> > putStrLn $ "x =" ++ maybe "" Text.unpack x > > > This allows you to provide a default value in your code for when the > column is NULL. > > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. > -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From mattei at oca.eu Wed Dec 19 09:34:08 2018 From: mattei at oca.eu (Damien Mattei) Date: Wed, 19 Dec 2018 10:34:08 +0100 Subject: [Haskell-cafe] (SPAM 3)Re: handling NULL value in database query with Maybe (or other ...) In-Reply-To: References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> <20181218151639.jv3j3rkmgwhxdk4e@weber> <5C191377.3040602@oca.eu> Message-ID: <5C1A1090.4060507@oca.eu> i had many answers, i can not answer to all,first thanks just afew words, i did not want to have a C beahvior at all,i try to escape from the C world... (the solution with Just and Nothing help a lot) i espected something like that too, the answer have been given to me in comp.lang.haskell: bd_rows_WDS :: [Maybe Text] <- query conn qry_head_WDS (Only (name::String)) but it fails to compile: *Main> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:213:5: error: Illegal type signature: ‘[Maybe Text]’ Type signatures are only allowed in patterns with ScopedTypeVariables | 213 | bd_rows_WDS :: [Maybe Text] <- query conn qry_head_WDS (Only (name::String)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Failed, no modules loaded. and i completely agree that Haskell is more safe than C/C++ even if as quoted here: https://esham.io/ it requires ,to do basic things " a Ph.D. and three Monoid instances "... quoted from "But zsh in particular lets you write text manipulation one-liners which in Haskell would require a Ph.D. and three Monoid instances. " :-) Le 18/12/2018 20:06, Michael Walker a écrit : > On Tue, 18 Dec 2018 at 15:34, Damien Mattei wrote: >> >> ok well i do not want to open a discussion here, but i do not see any >> benefit in Haskell using Nothing and Just compared to other language, >> it's the same than if i had written in C something like : >> if (x == NULL) >> printf("NULL\n"); >> else >> printf("%s",*x); >> >> i expected more from Haskell... > > Well, you have to remember to do that in C, but in Haskell the > compiler won't let you use a "Maybe a" as an "a". They're totally > different things. > > That seems a pretty huge benefit to me, even ignoring everything else. > What more could you want? > -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From bertram.felgenhauer at googlemail.com Wed Dec 19 11:31:46 2018 From: bertram.felgenhauer at googlemail.com (Bertram Felgenhauer) Date: Wed, 19 Dec 2018 12:31:46 +0100 Subject: [Haskell-cafe] Timing out a pure evaluation of an expression I did not write myself In-Reply-To: References: <20181119202651.GH4122@straasha.imrryr.org> <20181129011021.GB4122@straasha.imrryr.org> Message-ID: <20181219113145.GG16230@24f89f8c-e6a1-4e75-85ee-bb8a3743bb9f> Ryan Reich wrote: > I expected something like that. I'm all the way back in ghc-8.2.2, but I > think what this really shows is that the flag is unreliable and > version-dependent. The program terminates for me with ghc 8.0.2, 8.2.2, 8.4.3, and 8.6.1, if compiled with -O -fno-omit-yields; of the versions that I have around only version 7.8.4 supports -fno-omit-yields but produces a non-terminating program. This is on x86-64. I suspect that the real problem is that ghc's recompilation check does not take -fno-omit-yields into account before version 8.4.1, so you have to force a clean build for the flag to take effect. Cheers, Bertram From bertram.felgenhauer at googlemail.com Wed Dec 19 11:32:19 2018 From: bertram.felgenhauer at googlemail.com (Bertram Felgenhauer) Date: Wed, 19 Dec 2018 12:32:19 +0100 Subject: [Haskell-cafe] Timing out a pure evaluation of an expression I did not write myself In-Reply-To: References: <20181119202651.GH4122@straasha.imrryr.org> <20181129011021.GB4122@straasha.imrryr.org> Message-ID: <20181219113219.GH16230@24f89f8c-e6a1-4e75-85ee-bb8a3743bb9f> Erik Hesselink wrote: > Hi Ryan, > > I'm not quite sure of your use case, but lambdabot/mueval do something like > this I think. From a brief look at the source [1] it seems they compute in > a separate thread, then in another thread, wait until the timeout then kill > the computation thread. Would something like that work for you? That is not the whole story; the above mechanism is subject to the same problems as the original poster's program. mueval actually comes with a wrapper program ("mueval", source: "watchdog.hs") that invokes the actual interpreter ("mueval-core", source: "main.hs") as a subprocess; both programs implement a timeout, but the wrapper kills the interpreter if the internal timeout fails. This machinery predates -fno-omit-yields. But it's still useful because it also protects against blocking unsafe foreign calls and other scenarios where the RTS can become completely unresponsive, as well as potential holes in -fno-omit-yields. Cheers, Bertram From aquagnu at gmail.com Wed Dec 19 12:24:02 2018 From: aquagnu at gmail.com (Paul) Date: Wed, 19 Dec 2018 14:24:02 +0200 Subject: [Haskell-cafe] (SPAM 3)Re: handling NULL value in database query with Maybe (or other ...) In-Reply-To: <5C1A1090.4060507@oca.eu> References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> <20181218151639.jv3j3rkmgwhxdk4e@weber> <5C191377.3040602@oca.eu> <5C1A1090.4060507@oca.eu> Message-ID: So, add this extension. I think it would be: {-# LANGUAGE ScopedTypeVariables #-} ... (bd_rows_WDS :: [Maybe Text]) <- query conn qry_head_WDS (Only (name::String)) @Ian: Example with unsafeCoerce is not correct: how is "unsafeCoerce" related to Maybe/pattern matching? True is that Haskell is not safe, for example, it has unsafe functions fromJust, etc, while pattern-matching is only the right way to "extract" value from Maybe (OK, also "maybe" function). Ian, by the way, how can you guarantee that Segmentation Fault will not happen in Haskell application? I hit even freezing of Haskell apps, Haskell is not a language with such assertions. May be it will be Rust, but Haskell - never. 19.12.2018 11:34, Damien Mattei wrote: > i had many answers, i can not answer to all,first thanks > just afew words, i did not want to have a C beahvior at all,i try to > escape from the C world... > (the solution with Just and Nothing help a lot) > i espected something like that too, the answer have been given to me in > comp.lang.haskell: > > bd_rows_WDS :: [Maybe Text] <- query conn qry_head_WDS (Only > (name::String)) > > but it fails to compile: > > *Main> :load UpdateSidonie > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > UpdateSidonie.hs:213:5: error: > Illegal type signature: ‘[Maybe Text]’ > Type signatures are only allowed in patterns with ScopedTypeVariables > | > 213 | bd_rows_WDS :: [Maybe Text] <- query conn qry_head_WDS (Only > (name::String)) > | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > Failed, no modules loaded. > > and i completely agree that Haskell is more safe than C/C++ > even if as quoted here: https://esham.io/ > it requires ,to do basic things " a Ph.D. and three Monoid instances "... > > quoted from "But zsh in particular lets you write text manipulation > one-liners which in Haskell would require a Ph.D. and three Monoid > instances. " > :-) > > Le 18/12/2018 20:06, Michael Walker a écrit : >> On Tue, 18 Dec 2018 at 15:34, Damien Mattei wrote: >>> ok well i do not want to open a discussion here, but i do not see any >>> benefit in Haskell using Nothing and Just compared to other language, >>> it's the same than if i had written in C something like : >>> if (x == NULL) >>> printf("NULL\n"); >>> else >>> printf("%s",*x); >>> >>> i expected more from Haskell... >> Well, you have to remember to do that in C, but in Haskell the >> compiler won't let you use a "Maybe a" as an "a". They're totally >> different things. >> >> That seems a pretty huge benefit to me, even ignoring everything else. >> What more could you want? >> From svenpanne at gmail.com Wed Dec 19 14:03:21 2018 From: svenpanne at gmail.com (Sven Panne) Date: Wed, 19 Dec 2018 15:03:21 +0100 Subject: [Haskell-cafe] (SPAM 3)Re: handling NULL value in database query with Maybe (or other ...) In-Reply-To: References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> <20181218151639.jv3j3rkmgwhxdk4e@weber> <5C191377.3040602@oca.eu> <5C1A1090.4060507@oca.eu> Message-ID: Am Mi., 19. Dez. 2018 um 13:24 Uhr schrieb Paul : > [...] @Ian: Example with unsafeCoerce is not correct: how is > "unsafeCoerce" > related to Maybe/pattern matching? I think Ian just wanted to demonstrate that it is possible to crash Haskell programs in the same way as C programs if you really want to. OTOH, the name "unsafeCoerce" of the function used and its type (a -> b) alone should be very visible warning signs. ;-) Mere mortals should better forget about its existence, but unsafeCoerce can be useful if it is wrapped correctly. So it's a bit like a buzz saw: Quite useful if you need it, but *very* dangerous unless you know what you're doing... > True is that Haskell is not safe, for > example, it has unsafe functions fromJust, etc, while pattern-matching > is only the right way to "extract" value from Maybe (OK, also "maybe" > function). If you consider a language "safe" or not depends on your POV: Haskell is safe in the sense that programs written in it (without unsafeFOO stuff and without any FFI involved) do not segfault randomly like e.g. C programs. fromJust uses non-exhaustive pattern matching, which raises an exception if it encounters Nothing. This is fundametally different from e.g. dereferencing NULL/nullptr or accessing random memory. > Ian, by the way, how can you guarantee that Segmentation > Fault will not happen in Haskell application? I hit even freezing of > Haskell apps, Haskell is not a language with such assertions. May be it > will be Rust, but Haskell - never. > Every turing complete language *will* include the possibility of non-termination (which is what I guess you mean by "freezing), so this part is irrelevant. But even if you ignore that, every useful programming language on earth will give you the possibility of crashing, if you want it or not: At one point you will need to call out to native/C land to use OS and/or library functionality. Well, unless you want to rewrite your OS and all libraries in your shiny new and safe language... -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattei at oca.eu Wed Dec 19 16:14:47 2018 From: mattei at oca.eu (Damien Mattei) Date: Wed, 19 Dec 2018 17:14:47 +0100 Subject: [Haskell-cafe] handling NULL value in database query with Maybe (or other ...) In-Reply-To: <87sgytolp9.fsf@home.blind.guru> References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> <20181218151639.jv3j3rkmgwhxdk4e@weber> <5C191377.3040602@oca.eu> <87sgytolp9.fsf@home.blind.guru> Message-ID: <5C1A6E77.8010602@oca.eu> thank tou for your C/HASKELL "rosetta stone" about the Monad it helps a lot understanding the thing... i always thougt Monads are powerful but they are not easy sot manipulates syntactically for a beginner in Haskell. yes in fact what i secretly expected was a way to discard NULL fields automagically and it seems really possible with Haskell. Le 19/12/2018 11:27, Mario Lang a écrit : > Damien Mattei writes: > >> using Nothing and Just compared to other language, it's the same than >> if i had written in C something like : >> if (x == NULL) printf("NULL\n"); >> else printf("%s",*x); >> >> i expected more from Haskell... > > Haskell actually offers more. > > 1. The type of "Maybe a" prevents you from ignoring the fact that "a" might > be null. In C, you can accidentally write > > printf("%s",*x); > > and risking a segfault. The compiler will not care. IN Haskell, the > types dont even allow you to write something like that. You would be > forced to check for Just or Nothing in one of several ways. > > Now, "Maybe a" doesn't only limit your abilities, it also offers you the > functions from the Functor, Applicative and Monad typeclasses. > > 2. Functor allows you to apply a function to the "a", as long as there is > some "a" inside the "Maybe a". So, "fmap f x" is roughly equivalent to: > > typeOfA f(typeOfA); > typeOfA *x func(typeOfA *x) { > if (x) { > typeOfA *val = malloc(sizeof(typeOfA)); > *val = f(*x); > return val; > } > return NULL; > } > func(x); > > (note that pure Haskell doesn't have assignment, so the translation to C > is a little bit more verbose then it might be if you were using values > on the stack.) i tried this: let resFMAP = fmap (\(Only a) -> (putStrLn ("a =" ++ Text.unpack a))) bd_rows_WDS but compile complains now that i use a Maybe variable instead of a plain one,strange because this exactly what i expected from Maybe use it to automatically discard the Nothing values (avoiding to putStrln them): Prelude> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:293:75: error: • Couldn't match type ‘Maybe Text’ with ‘Text’ Expected type: [Only Text] Actual type: [Only (Maybe Text)] • In the second argument of ‘fmap’, namely ‘bd_rows_WDS’ In the expression: fmap (\ (Only a) -> (putStrLn ("a =" ++ unpack a))) bd_rows_WDS In an equation for ‘resFMAP’: resFMAP = fmap (\ (Only a) -> (putStrLn ("a =" ++ unpack a))) bd_rows_WDS | 293 | let resFMAP = fmap (\(Only a) -> (putStrLn ("a =" ++ Text.unpack a))) bd_rows_WDS | ^^^^^^^^^^^ Failed, no modules loaded. bd_rows_WDS is defined like this with a Maybe: (bd_rows_WDS :: [Only (Maybe Text)]) <- query conn qry_head_WDS (Only (name::String)) anyway i know enought in haskell now to remove myself the Nothing (NULL) values of the list doing that (it worked): -- remove the records having N°BD NULL let fltWDS = Prelude.filter (\(Only a) -> case a of Nothing -> False Just a -> True) bd_rows_WDS > > So you do not need to write an explicit if in Haskell. The Functor > instance of Maybe "knows" how to deal will null cases. > In particular, if it encounters a Nothing, it returns a Nothing, > ignoring the provided function. > > 3. Applicative allows you to apply a function to the "a"s of several "Maybe a" > values, returning a Maybe wrapping the result of that function. > So "f <$> x <*> y" is equivalent to > > typeOfA f(TypeOfA); > typeOfA *func(typeOfA *x, typeOfA *y) { > if (x && y) { > typeOfA *val = malloc(sizeof(typeOfA)); > *val = f(*x, *y); > return val; > } > return NULL; > } > func(x, y); > > The amount of boilerplate eliminated grows. > > 3. Monad allows you to chain several null-checks without having to write > out the nesting. This time, f, g and h return a "Maybe a", not just an "a": > > do > a <- f x > b <- g a > h b > > or > > f x >>= \a -> g a >>= \b -> h b > > is equvalent to something like > > typeOfA *f(typeOfA); > typeOfA *g(typeOfA); > typeOfA *h(typeOfA); > typeOfA *func(typeOfA x) { > if (x) { > type *a = f(*x); > if (a) { > type *b = g(*a); > if (b) { > return f(*b); > } > } > } > return NULL; > } > > or, in Haskell: > > case f x of > Just a -> case g a of > Just b -> h b > Nothing -> Nothing > Nothing -> Nothing > > The Monad typeclass really pays off, as it saves you from doing the null > checks and dereferencing. The nested "if null then null" stuff goes all > away, and you can chain several functions together that return a > possible null value. > >> ok reading twice the article in link, i admit there should be some >> adavantage using Nothing instead of null, such as type, and genericity >> and not being spcecific to alloated memory as in C ... > > Exactly. As I see it, the Functor, Applicative and Monad typeclasses > of the Maybe type give you the tools > necessary to reduce the boilerplate that results from forcing you to > deal with each and every null case in your code. > -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From allbery.b at gmail.com Wed Dec 19 16:17:52 2018 From: allbery.b at gmail.com (Brandon Allbery) Date: Wed, 19 Dec 2018 11:17:52 -0500 Subject: [Haskell-cafe] handling NULL value in database query with Maybe (or other ...) In-Reply-To: <5C1A6E77.8010602@oca.eu> References: <5C18C8F3.5080708@oca.eu> <95bccfe8-867a-0b3d-1d6c-03af2fd4f0f5@gmail.com> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> <20181218151639.jv3j3rkmgwhxdk4e@weber> <5C191377.3040602@oca.eu> <87sgytolp9.fsf@home.blind.guru> <5C1A6E77.8010602@oca.eu> Message-ID: Haskell doesn't do "automatically"; the whole point is to force you to handle these kinds of cases, not "just make it somehow work" in ways you can't be certain are correct for your use case. On Wed, Dec 19, 2018 at 11:15 AM Damien Mattei wrote: > thank tou for your C/HASKELL "rosetta stone" about the Monad it helps a > lot understanding the thing... > > i always thougt Monads are powerful but they are not easy sot > manipulates syntactically for a beginner in Haskell. > > yes in fact what i secretly expected was a way to discard NULL fields > automagically and it seems really possible with Haskell. > > Le 19/12/2018 11:27, Mario Lang a écrit : > > Damien Mattei writes: > > > >> using Nothing and Just compared to other language, it's the same than > >> if i had written in C something like : > >> if (x == NULL) printf("NULL\n"); > >> else printf("%s",*x); > >> > >> i expected more from Haskell... > > > > Haskell actually offers more. > > > > 1. The type of "Maybe a" prevents you from ignoring the fact that "a" > might > > be null. In C, you can accidentally write > > > > printf("%s",*x); > > > > and risking a segfault. The compiler will not care. IN Haskell, the > > types dont even allow you to write something like that. You would be > > forced to check for Just or Nothing in one of several ways. > > > > Now, "Maybe a" doesn't only limit your abilities, it also offers you the > > functions from the Functor, Applicative and Monad typeclasses. > > > > 2. Functor allows you to apply a function to the "a", as long as there is > > some "a" inside the "Maybe a". So, "fmap f x" is roughly equivalent to: > > > > typeOfA f(typeOfA); > > typeOfA *x func(typeOfA *x) { > > if (x) { > > typeOfA *val = malloc(sizeof(typeOfA)); > > *val = f(*x); > > return val; > > } > > return NULL; > > } > > func(x); > > > > (note that pure Haskell doesn't have assignment, so the translation to C > > is a little bit more verbose then it might be if you were using values > > on the stack.) > > i tried this: > > let resFMAP = fmap (\(Only a) -> (putStrLn ("a =" ++ Text.unpack a))) > bd_rows_WDS > > but compile complains now that i use a Maybe variable instead of a plain > one,strange because this exactly what i expected from Maybe use it to > automatically discard the Nothing values (avoiding to putStrln them): > Prelude> :load UpdateSidonie > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > UpdateSidonie.hs:293:75: error: > • Couldn't match type ‘Maybe Text’ with ‘Text’ > Expected type: [Only Text] > Actual type: [Only (Maybe Text)] > • In the second argument of ‘fmap’, namely ‘bd_rows_WDS’ > In the expression: > fmap (\ (Only a) -> (putStrLn ("a =" ++ unpack a))) bd_rows_WDS > In an equation for ‘resFMAP’: > resFMAP > = fmap (\ (Only a) -> (putStrLn ("a =" ++ unpack a))) > bd_rows_WDS > | > 293 | let resFMAP = fmap (\(Only a) -> (putStrLn ("a =" ++ > Text.unpack a))) bd_rows_WDS > | > ^^^^^^^^^^^ > Failed, no modules loaded. > > bd_rows_WDS is defined like this with a Maybe: > > (bd_rows_WDS :: [Only (Maybe Text)]) <- query conn qry_head_WDS (Only > (name::String)) > > anyway i know enought in haskell now to remove myself the Nothing (NULL) > values of the list doing that (it worked): > > -- remove the records having N°BD NULL > let fltWDS = Prelude.filter (\(Only a) -> > case a of > Nothing -> False > Just a -> True) > bd_rows_WDS > > > > > So you do not need to write an explicit if in Haskell. The Functor > > instance of Maybe "knows" how to deal will null cases. > > In particular, if it encounters a Nothing, it returns a Nothing, > > ignoring the provided function. > > > > 3. Applicative allows you to apply a function to the "a"s of several > "Maybe a" > > values, returning a Maybe wrapping the result of that function. > > So "f <$> x <*> y" is equivalent to > > > > typeOfA f(TypeOfA); > > typeOfA *func(typeOfA *x, typeOfA *y) { > > if (x && y) { > > typeOfA *val = malloc(sizeof(typeOfA)); > > *val = f(*x, *y); > > return val; > > } > > return NULL; > > } > > func(x, y); > > > > The amount of boilerplate eliminated grows. > > > > 3. Monad allows you to chain several null-checks without having to write > > out the nesting. This time, f, g and h return a "Maybe a", not just an > "a": > > > > do > > a <- f x > > b <- g a > > h b > > > > or > > > > f x >>= \a -> g a >>= \b -> h b > > > > is equvalent to something like > > > > typeOfA *f(typeOfA); > > typeOfA *g(typeOfA); > > typeOfA *h(typeOfA); > > typeOfA *func(typeOfA x) { > > if (x) { > > type *a = f(*x); > > if (a) { > > type *b = g(*a); > > if (b) { > > return f(*b); > > } > > } > > } > > return NULL; > > } > > > > or, in Haskell: > > > > case f x of > > Just a -> case g a of > > Just b -> h b > > Nothing -> Nothing > > Nothing -> Nothing > > > > The Monad typeclass really pays off, as it saves you from doing the null > > checks and dereferencing. The nested "if null then null" stuff goes all > > away, and you can chain several functions together that return a > > possible null value. > > > >> ok reading twice the article in link, i admit there should be some > >> adavantage using Nothing instead of null, such as type, and genericity > >> and not being spcecific to alloated memory as in C ... > > > > Exactly. As I see it, the Functor, Applicative and Monad typeclasses > > of the Maybe type give you the tools > > necessary to reduce the boilerplate that results from forcing you to > > deal with each and every null case in your code. > > > > -- > Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -- brandon s allbery kf8nh allbery.b at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian at zenhack.net Wed Dec 19 19:35:34 2018 From: ian at zenhack.net (Ian Denhardt) Date: Wed, 19 Dec 2018 14:35:34 -0500 Subject: [Haskell-cafe] (SPAM 3)Re: handling NULL value in database query with Maybe (or other ...) In-Reply-To: References: <5C18C8F3.5080708@oca.eu> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> <20181218151639.jv3j3rkmgwhxdk4e@weber> <5C191377.3040602@oca.eu> <5C1A1090.4060507@oca.eu> Message-ID: <154524813486.1119.785891674796004716@localhost.localdomain> Quoting Sven Panne (2018-12-19 09:03:21) > > I think Ian just wanted to demonstrate that it is possible to crash > Haskell programs in the same way as C programs if you really want to. > OTOH, > the name "unsafeCoerce" of the function used and its type (a -> > b) alone should be very visible warning signs. ;-) Mere mortals should > better forget about its existence, ..and this was more my point -- while it *is* possible to cause the same bad behavior in Haskell as in C, the language is constructed in such a way that it's hard to do so by accident. > Ian, by the way, how can you guarantee that Segmentation > Fault will not happen in Haskell application? You can't, and indeed it has happened in the past, sometimes due to compiler bugs, sometimes due to misuse of stuff like unsafeCoerce or the FFI. But it's literally never happened to me personally. My point is it's not about guarantees so much as whether getting things right is easy. Forgetting to check for NULL in C is a massive source of real-world bugs. Forgetting to check for Nothing in Haskell isn't. Note that the distinction *does* matter if you're thinking of building something like lambdabot, where you may be running malicious code. But for most purposes it doesn't. From schernichkin at gmail.com Wed Dec 19 21:02:07 2018 From: schernichkin at gmail.com (=?UTF-8?B?0KHRgtCw0L3QuNGB0LvQsNCyINCn0LXRgNC90LjRh9C60LjQvQ==?=) Date: Thu, 20 Dec 2018 00:02:07 +0300 Subject: [Haskell-cafe] MVar considered harmful Message-ID: Recently I had an interesting discussion on MVars with cats-effect library designers. Cats-effect brings MVar synchronization primitive along with other IO stuff to the Scala programming language. I tried to persuade them to include some Control.Concurrent.MVar’s functions to the library but has failed completely. Moreover, now I think that MVar is a poor choice for basic synchronization primitive. Your may find discussion here https://github.com/typelevel/cats-effect/issues/451 and event try to advocate, tl;dr. Anyway, what is so wrong with MVar? 1. It’s complex. Each MVar has 2 state transitions, each may block. 2. It does not play well in presence of asynchronous exceptions. More specifically, `take` and `put` operations should be balanced (each `take` must be followed by `put`) this force programmer to mask asynchronous exceptions during the MVar acquisition and since `take` function may block, this will delay task cancelation. Well, you may argue what the `takeMVar` function is actually interruptible, but I’m going to show an easier approach which renders interpretability magic unnecessary. What could be the sensible alternative? Guy from the cats-effect suggested me IVar + atomic reference (IORef). This pattern separates concern of blocking (synchronization) from the atomic mutation. So everything can be represented as atomic reference with IVar inside. Just look at this beautiful mutex implementation https://github.com/ovotech/fs2-kafka/blob/master/src/main/scala/fs2/kafka/internal/Synchronized.scala (By ”beautiful” I mean approach itself of course, but not the Scala’s syntax. Scala is one of most ugliest girls after C++ I was forced to date with by my employer for money. Thankfully he didn’t force me to do the same things with her grandma Java). For people who don’t read Scala, the approach is fairly simple. Each thread which want to touch mutex, will create IVar, atomically swap it in the IORef masked (note, that IORef’s operations non-blocking), unmask and wait for previous become available IVar *unmasked*. Then it will either perform it’s operations or fail due to the interruption or exception and trigger newly installed IVar anyway. It just works. Without any «interruptible» magic. So, which benefits can we get? 1. Simpler implementation of basic primitives. Obliviously IORef is fairly simple. IVar is also mind be simpler than MVar, and possibly faster (just “possibly”, I don’t know how it’s implemented, but I guess lesser state transitions implies less logic). 2. Simplified deadlock analysis. Really, we have only IVar with only one state transition and only one potentially blocking operation. 3. Magicless support of interruptions. We don’t need to separate mask/uninterruptibleMask anymore, because all updates are non-blocking, and all waits are unmasked. -------------- next part -------------- An HTML attachment was scrubbed... URL: From b at chreekat.net Wed Dec 19 21:33:51 2018 From: b at chreekat.net (Bryan Richter) Date: Wed, 19 Dec 2018 23:33:51 +0200 Subject: [Haskell-cafe] MVar considered harmful In-Reply-To: References: Message-ID: Interesting. I have indeed seen enough cases of "Blocked indefinitely on MVar" to suggest they might be difficult to handle correctly! On Wed, Dec 19, 2018, 23:02 Станислав Черничкин Recently I had an interesting discussion on MVars with cats-effect library > designers. Cats-effect brings MVar synchronization primitive along with > other IO stuff to the Scala programming language. I tried to persuade them > to include some Control.Concurrent.MVar’s functions to the library but has > failed completely. Moreover, now I think that MVar is a poor choice for > basic synchronization primitive. Your may find discussion here > https://github.com/typelevel/cats-effect/issues/451 and event try to > advocate, tl;dr. Anyway, what is so wrong with MVar? > > 1. It’s complex. Each MVar has 2 state transitions, each may block. > > 2. It does not play well in presence of asynchronous exceptions. > More specifically, `take` and `put` operations should be balanced (each > `take` must be followed by `put`) this force programmer to mask > asynchronous exceptions during the MVar acquisition and since `take` > function may block, this will delay task cancelation. Well, you may argue > what the `takeMVar` function is actually interruptible, but I’m going to > show an easier approach which renders interpretability magic unnecessary. > > What could be the sensible alternative? Guy from the cats-effect suggested > me IVar + atomic reference (IORef). This pattern separates concern of > blocking (synchronization) from the atomic mutation. So everything can be > represented as atomic reference with IVar inside. Just look at this > beautiful mutex implementation > https://github.com/ovotech/fs2-kafka/blob/master/src/main/scala/fs2/kafka/internal/Synchronized.scala > (By ”beautiful” I mean approach itself of course, but not the Scala’s > syntax. Scala is one of most ugliest girls after C++ I was forced to date > with by my employer for money. Thankfully he didn’t force me to do the same > things with her grandma Java). > > For people who don’t read Scala, the approach is fairly simple. Each > thread which want to touch mutex, will create IVar, atomically swap it in > the IORef masked (note, that IORef’s operations non-blocking), unmask and > wait for previous become available IVar *unmasked*. Then it will either > perform it’s operations or fail due to the interruption or exception and > trigger newly installed IVar anyway. It just works. Without any > «interruptible» magic. > > So, which benefits can we get? > > 1. Simpler implementation of basic primitives. Obliviously IORef is > fairly simple. IVar is also mind be simpler than MVar, and possibly faster > (just “possibly”, I don’t know how it’s implemented, but I guess lesser > state transitions implies less logic). > > 2. Simplified deadlock analysis. Really, we have only IVar with > only one state transition and only one potentially blocking operation. > > 3. Magicless support of interruptions. We don’t need to separate > mask/uninterruptibleMask anymore, because all updates are non-blocking, and > all waits are unmasked. > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Wed Dec 19 21:43:42 2018 From: allbery.b at gmail.com (Brandon Allbery) Date: Wed, 19 Dec 2018 16:43:42 -0500 Subject: [Haskell-cafe] MVar considered harmful In-Reply-To: References: Message-ID: MVar is very low level. You almost never want to use it directly unless you're building a higher level synchronization mechanism from scratch. On Wed, Dec 19, 2018 at 4:34 PM Bryan Richter wrote: > Interesting. I have indeed seen enough cases of "Blocked indefinitely on > MVar" to suggest they might be difficult to handle correctly! > > On Wed, Dec 19, 2018, 23:02 Станислав Черничкин wrote: > >> Recently I had an interesting discussion on MVars with cats-effect >> library designers. Cats-effect brings MVar synchronization primitive along >> with other IO stuff to the Scala programming language. I tried to persuade >> them to include some Control.Concurrent.MVar’s functions to the library >> but has failed completely. Moreover, now I think that MVar is a poor choice >> for basic synchronization primitive. Your may find discussion here >> https://github.com/typelevel/cats-effect/issues/451 and event try to >> advocate, tl;dr. Anyway, what is so wrong with MVar? >> >> 1. It’s complex. Each MVar has 2 state transitions, each may >> block. >> >> 2. It does not play well in presence of asynchronous exceptions. >> More specifically, `take` and `put` operations should be balanced (each >> `take` must be followed by `put`) this force programmer to mask >> asynchronous exceptions during the MVar acquisition and since `take` >> function may block, this will delay task cancelation. Well, you may argue >> what the `takeMVar` function is actually interruptible, but I’m going to >> show an easier approach which renders interpretability magic unnecessary. >> >> What could be the sensible alternative? Guy from the cats-effect >> suggested me IVar + atomic reference (IORef). This pattern separates >> concern of blocking (synchronization) from the atomic mutation. So >> everything can be represented as atomic reference with IVar inside. Just >> look at this beautiful mutex implementation >> https://github.com/ovotech/fs2-kafka/blob/master/src/main/scala/fs2/kafka/internal/Synchronized.scala >> (By ”beautiful” I mean approach itself of course, but not the Scala’s >> syntax. Scala is one of most ugliest girls after C++ I was forced to date >> with by my employer for money. Thankfully he didn’t force me to do the same >> things with her grandma Java). >> >> For people who don’t read Scala, the approach is fairly simple. Each >> thread which want to touch mutex, will create IVar, atomically swap it in >> the IORef masked (note, that IORef’s operations non-blocking), unmask and >> wait for previous become available IVar *unmasked*. Then it will either >> perform it’s operations or fail due to the interruption or exception and >> trigger newly installed IVar anyway. It just works. Without any >> «interruptible» magic. >> >> So, which benefits can we get? >> >> 1. Simpler implementation of basic primitives. Obliviously IORef >> is fairly simple. IVar is also mind be simpler than MVar, and possibly >> faster (just “possibly”, I don’t know how it’s implemented, but I guess >> lesser state transitions implies less logic). >> >> 2. Simplified deadlock analysis. Really, we have only IVar with >> only one state transition and only one potentially blocking operation. >> >> 3. Magicless support of interruptions. We don’t need to separate >> mask/uninterruptibleMask anymore, because all updates are non-blocking, and >> all waits are unmasked. >> _______________________________________________ >> Haskell-Cafe mailing list >> To (un)subscribe, modify options or view archives go to: >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> Only members subscribed via the mailman list are allowed to post. > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -- brandon s allbery kf8nh allbery.b at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From reiner.pope at gmail.com Wed Dec 19 21:49:47 2018 From: reiner.pope at gmail.com (Reiner Pope) Date: Wed, 19 Dec 2018 13:49:47 -0800 Subject: [Haskell-cafe] Upload new version of indexed-extras or let me take over In-Reply-To: References: Message-ID: (haskell-cafe to bcc) Hi Yuji, thanks for the ping and sorry for the delay. Alexis (cc'd) took over ownership of indexed and indexed-extras at the beginning of this year, but apparently her permissions to upload packages to Hackage got reset by a Hackage reset. I've now fixed that, so she can reupload now (she was generally much more prompt than me). I'll upload a new version tonight. Not required, but if you like I'm also happy to add you on the GitHub project and the Hackage packages if you'd like to give me your details. Reiner On Sat, Dec 15, 2018 at 1:42 AM Yuji Yamamoto wrote: > Hello, this is a reminder of the message I sent (only to Reiner) about > three weeks ago. > > I'm developing some libraries in Haskell with your package indexed-extras > . > I found the package can't be built with the latest bifunctor package due > to its version constraint. > I sent a pull request > to fix the problem and it has already been merged. > Can you release the new version on Hackage? > It's now the biggest obstacle developing my libraries depending on it. > > If you can't maintain the package anymore, I'm willing to take over. > Thanks in advance. > > > -- > 山本悠滋 > twitter: @igrep > GitHub: https://github.com/igrep > GitLab: https://gitlab.com/igrep > Facebook: http://www.facebook.com/igrep > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian at zenhack.net Wed Dec 19 22:14:47 2018 From: ian at zenhack.net (Ian Denhardt) Date: Wed, 19 Dec 2018 17:14:47 -0500 Subject: [Haskell-cafe] MVar considered harmful In-Reply-To: References: Message-ID: <154525768780.3676.10247480171207787756@localhost.localdomain> A few thoughts: * IIRC, MVars (in Haskell anyway) also have some fairness guarantees, which I don't see otherwise mentioned in the discussion so far. Compare to STM, where large transactions are susceptible to starvation. * If the goal is to have a simpler base primitive on which to build, everything has to boil down to compare-and-swap, load-linked/store-conditional, etc -- whatever the machine provides. When you start talking about even mutexes and semaphores, you're already dealing with higher-level abstractions, so the thinking about what's the right "primitive" seems silly to me at that point; you should be thinking about what the high-level (user) code should be able to do, and then figure out how to meet in the middle. * If what you're after is *composable* concurrency, simpler locks won't get you that. STM is the best general solution I've seen for this, and if you're doing concurrency stuff in Haskell, I would say use STM unless you have a specific reason to do something else. * Re: async exceptions, you're in the same situation with MVars as you are with all resource-acquiring IO actions in Haskell. `withMVar` and friends cover async-exception safety, and you can't get rid of mask and friends by swapping out MVars with another primitive anyway, because you still need them for acquiring other (non-concurrency related) resources, like files. -Ian From mattei at oca.eu Thu Dec 20 09:38:41 2018 From: mattei at oca.eu (Damien Mattei) Date: Thu, 20 Dec 2018 10:38:41 +0100 Subject: [Haskell-cafe] (SPAM 3)Re: handling NULL value in database query with Maybe (or other ...) In-Reply-To: <154524813486.1119.785891674796004716@localhost.localdomain> References: <5C18C8F3.5080708@oca.eu> <5C18D5E5.8090703@oca.eu> <5C190797.3080701@oca.eu> <20181218151639.jv3j3rkmgwhxdk4e@weber> <5C191377.3040602@oca.eu> <5C1A1090.4060507@oca.eu> <154524813486.1119.785891674796004716@localhost.localdomain> Message-ID: <5C1B6321.3060908@oca.eu> Le 19/12/2018 20:35, Ian Denhardt a écrit : > Quoting Sven Panne (2018-12-19 09:03:21) >> >> I think Ian just wanted to demonstrate that it is possible to crash >> Haskell programs in the same way as C programs if you really want to. >> OTOH, > >> the name "unsafeCoerce" all is in the name... ;-) it's unsafe and coercitive... i will always try to avoid this in my code... of the function used and its type (a -> >> b) alone should be very visible warning signs. ;-) Mere mortals should >> better forget about its existence, > > ..and this was more my point -- while it *is* possible to cause the > same bad behavior in Haskell as in C, the language is constructed in > such a way that it's hard to do so by accident. > >> Ian, by the way, how can you guarantee that Segmentation >> Fault will not happen in Haskell application? > > You can't, and indeed it has happened in the past, sometimes due to > compiler bugs, sometimes due to misuse of stuff like unsafeCoerce or the > FFI. > > But it's literally never happened to me personally. > > My point is it's not about guarantees so much as whether getting things > right is easy. Forgetting to check for NULL in C is a massive source of > real-world bugs. Forgetting to check for Nothing in Haskell isn't. > > Note that the distinction *does* matter if you're thinking of building > something like lambdabot, where you may be running malicious code. But > for most purposes it doesn't. > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. > -- Damien.Mattei at unice.fr, Damien.Mattei at oca.eu, UNS / OCA / CNRS From damien.mattei at gmail.com Sat Dec 22 08:52:18 2018 From: damien.mattei at gmail.com (Damien Mattei) Date: Sat, 22 Dec 2018 09:52:18 +0100 Subject: [Haskell-cafe] trace output statements Message-ID: i have this function: -- this function will return th N°BD from Sidonie for a given name -- note: names have been standardized between Sidonie and WDS getBD :: Connection -> String -> IO Float getBD conn name = trace "Entering getBD" noBDfp where qry_head = "select `N° BD` from Coordonnées where Nom = ?" :: Query bd_rows :: IO [Only Text] bd_rows = query conn qry_head (Only (name::String)) -- noBDtxt :: [Text] -- noBDtxt = fromOnly (Prelude.head bd_rows) -- noBDtxt :: IO [Text] -- lg = fmap Prelude.length bd_rows -- lg2 = fmap show lg noBDtxt :: IO Text -- noBDtxt = trace "lg " (fmap (fromOnly . Prelude.head) bd_rows) noBDtxt = trace "assigning noBDtxt" (fmap (fromOnly . Prelude.head) bd_rows) -- noBDstr :: String -- noBDstr = Text.unpack noBDtxt noBDstr :: IO String noBDstr = trace "assigning noBDstr" (fmap Text.unpack noBDtxt) -- noBDfp = read $ noBDstr :: Float noBDfp :: IO Float noBDfp = fmap read noBDstr call by : let lstBD = Prelude.map (\elem -> getBD conn (Text.unpack (fst elem))) rows it works ok, in fact at some point it fails due to NULL sql value not again handle correctly , i have inserted trace statement that output variable, i understand it's not really good becaus it breaks the purity of haskell function, perheaps for this reason i have strange behavior of output: ... Entering getBD assigning noBDstr assigning noBDtxt Entering getBD assigning noBDstr assigning noBDtxt Entering getBD assigning noBDstr assigning noBDtxt *** Exception: UnexpectedNull {errSQLType = "VarString", errHaskellType = "Text", errFieldName = "N\194\176 BD", errMessage = "unexpected null in table Coordonn\195\169es of database sidonie"} *Main> you will notice noBDstr seems to be assigned before noBDtxt, but in the code i have the statements in this order: noBDtxt = trace "assigning noBDtxt" (fmap (fromOnly . Prelude.head) bd_rows) noBDstr :: IO String noBDstr = trace "assigning noBDstr" (fmap Text.unpack noBDtxt) i just want to understand wht's happening, this is not critical for code as it works... any idea? Damien -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk Sun Dec 23 07:39:42 2018 From: tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk (Tom Ellis) Date: Sun, 23 Dec 2018 07:39:42 +0000 Subject: [Haskell-cafe] trace output statements In-Reply-To: References: Message-ID: <20181223073942.kiyhjyx3iwa5kvd5@weber> On Sat, Dec 22, 2018 at 09:52:18AM +0100, Damien Mattei wrote: > i have inserted trace statement that output variable > ... i have strange behavior of output: Let's take a simpler example. Do you understand why the trace statments from this small program appear in the order that they do? (And for what it's worth I really think you'll be better off writing programs using do notation). % cat test.hs import Debug.Trace result = let a = trace "evaluating a" 2 b = trace "evaluating b" 10 c = trace "evaluating c" (a + b) in c ~% ghci -e result test.hs evaluating c evaluating b evaluating a 12 From damien.mattei at gmail.com Sun Dec 23 13:08:57 2018 From: damien.mattei at gmail.com (Damien Mattei) Date: Sun, 23 Dec 2018 14:08:57 +0100 Subject: [Haskell-cafe] trace output statements In-Reply-To: <20181223073942.kiyhjyx3iwa5kvd5@weber> References: <20181223073942.kiyhjyx3iwa5kvd5@weber> Message-ID: lazyness....? On Sun, Dec 23, 2018 at 8:40 AM Tom Ellis < tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > On Sat, Dec 22, 2018 at 09:52:18AM +0100, Damien Mattei wrote: > > i have inserted trace statement that output variable > > ... i have strange behavior of output: > > Let's take a simpler example. Do you understand why the trace statments > from this small program appear in the order that they do? (And for what > it's worth I really think you'll be better off writing programs using do > notation). > > > % cat test.hs > import Debug.Trace > > result = > let a = trace "evaluating a" 2 > b = trace "evaluating b" 10 > c = trace "evaluating c" (a + b) > in c > ~% ghci -e result test.hs > evaluating c > evaluating b > evaluating a > 12 > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk Sun Dec 23 15:11:28 2018 From: tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk (Tom Ellis) Date: Sun, 23 Dec 2018 15:11:28 +0000 Subject: [Haskell-cafe] trace output statements In-Reply-To: References: <20181223073942.kiyhjyx3iwa5kvd5@weber> Message-ID: <20181223151128.qcb6b6tnqnhwpktl@weber> Yes, exactly! On Sun, Dec 23, 2018 at 02:08:57PM +0100, Damien Mattei wrote: > lazyness....? > > On Sun, Dec 23, 2018 at 8:40 AM Tom Ellis < > tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > > > On Sat, Dec 22, 2018 at 09:52:18AM +0100, Damien Mattei wrote: > > > i have inserted trace statement that output variable > > > ... i have strange behavior of output: > > > > Let's take a simpler example. Do you understand why the trace statments > > from this small program appear in the order that they do? (And for what > > it's worth I really think you'll be better off writing programs using do > > notation). > > > > > > % cat test.hs > > import Debug.Trace > > > > result = > > let a = trace "evaluating a" 2 > > b = trace "evaluating b" 10 > > c = trace "evaluating c" (a + b) > > in c > > ~% ghci -e result test.hs > > evaluating c > > evaluating b > > evaluating a > > 12 From damien.mattei at gmail.com Sun Dec 23 15:44:57 2018 From: damien.mattei at gmail.com (Damien Mattei) Date: Sun, 23 Dec 2018 16:44:57 +0100 Subject: [Haskell-cafe] trace output statements In-Reply-To: <20181223151128.qcb6b6tnqnhwpktl@weber> References: <20181223073942.kiyhjyx3iwa5kvd5@weber> <20181223151128.qcb6b6tnqnhwpktl@weber> Message-ID: i will spent part of my christmas holidays, learning seriously Haskell...fonctor,monads,IO.... i hope next year i will ask less silly question ;-) in the haskell-cafe mailing list. For now i'm sticked with problems with IO Monads,database IO, and i have to revamp all my code because it's not working as i want, having code in main is ok but if i put some part of code in a simple function it fails to compile or worse compile but ouput nothing or give/require me /back IO * things that are a nightmare to deal with... i must admit i never has such difficulty learning a language... i think learning Monads from scratch again will help me, the frustrating part of all this is that i'm only trying to do database manipulation that would be easy in python or Scheme. I do not want to blame myself more, i think that Haskell is too abstract for basic things such as IO, it's ok to be abstract for hard problems,C++ with standart template library for example but not for reading an input from a database and manipulate the data simply... On Sun, Dec 23, 2018 at 4:11 PM Tom Ellis < tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > Yes, exactly! > > On Sun, Dec 23, 2018 at 02:08:57PM +0100, Damien Mattei wrote: > > lazyness....? > > > > On Sun, Dec 23, 2018 at 8:40 AM Tom Ellis < > > tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > > > > > On Sat, Dec 22, 2018 at 09:52:18AM +0100, Damien Mattei wrote: > > > > i have inserted trace statement that output variable > > > > ... i have strange behavior of output: > > > > > > Let's take a simpler example. Do you understand why the trace > statments > > > from this small program appear in the order that they do? (And for > what > > > it's worth I really think you'll be better off writing programs using > do > > > notation). > > > > > > > > > % cat test.hs > > > import Debug.Trace > > > > > > result = > > > let a = trace "evaluating a" 2 > > > b = trace "evaluating b" 10 > > > c = trace "evaluating c" (a + b) > > > in c > > > ~% ghci -e result test.hs > > > evaluating c > > > evaluating b > > > evaluating a > > > 12 > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk Sun Dec 23 15:54:24 2018 From: tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk (Tom Ellis) Date: Sun, 23 Dec 2018 15:54:24 +0000 Subject: [Haskell-cafe] trace output statements In-Reply-To: References: <20181223073942.kiyhjyx3iwa5kvd5@weber> <20181223151128.qcb6b6tnqnhwpktl@weber> Message-ID: <20181223155424.7bhu4fyz7ns47pv4@weber> I think forgetting about monads and just using do-notation will help you. On Sun, Dec 23, 2018 at 04:44:57PM +0100, Damien Mattei wrote: > i think learning Monads from scratch again will help me > > On Sun, Dec 23, 2018 at 4:11 PM Tom Ellis < > tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > > > Yes, exactly! > > > > On Sun, Dec 23, 2018 at 02:08:57PM +0100, Damien Mattei wrote: > > > lazyness....? > > > > > > On Sun, Dec 23, 2018 at 8:40 AM Tom Ellis < > > > tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > > > > > > > On Sat, Dec 22, 2018 at 09:52:18AM +0100, Damien Mattei wrote: > > > > > i have inserted trace statement that output variable > > > > > ... i have strange behavior of output: > > > > > > > > Let's take a simpler example. Do you understand why the trace > > statments > > > > from this small program appear in the order that they do? (And for > > what > > > > it's worth I really think you'll be better off writing programs using > > do > > > > notation). > > > > > > > > > > > > % cat test.hs > > > > import Debug.Trace > > > > > > > > result = > > > > let a = trace "evaluating a" 2 > > > > b = trace "evaluating b" 10 > > > > c = trace "evaluating c" (a + b) > > > > in c > > > > ~% ghci -e result test.hs > > > > evaluating c > > > > evaluating b > > > > evaluating a > > > > 12 > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. From eraker at gmail.com Sun Dec 23 20:19:04 2018 From: eraker at gmail.com (erik) Date: Sun, 23 Dec 2018 12:19:04 -0800 Subject: [Haskell-cafe] trace output statements In-Reply-To: <20181223073942.kiyhjyx3iwa5kvd5@weber> References: <20181223073942.kiyhjyx3iwa5kvd5@weber> Message-ID: Tom, Why does "b" evaluate before "a" in your example? I would have thought left-hand and then right-hand if needed. I'm on my phone but I'd like to try the same example with booleans and `&&` instead of `+`. Erik On Sat, Dec 22, 2018, 11:40 PM Tom Ellis < tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk wrote: > On Sat, Dec 22, 2018 at 09:52:18AM +0100, Damien Mattei wrote: > > i have inserted trace statement that output variable > > ... i have strange behavior of output: > > Let's take a simpler example. Do you understand why the trace statments > from this small program appear in the order that they do? (And for what > it's worth I really think you'll be better off writing programs using do > notation). > > > % cat test.hs > import Debug.Trace > > result = > let a = trace "evaluating a" 2 > b = trace "evaluating b" 10 > c = trace "evaluating c" (a + b) > in c > ~% ghci -e result test.hs > evaluating c > evaluating b > evaluating a > 12 > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian at zenhack.net Sun Dec 23 22:24:41 2018 From: ian at zenhack.net (Ian Denhardt) Date: Sun, 23 Dec 2018 17:24:41 -0500 Subject: [Haskell-cafe] trace output statements In-Reply-To: References: <20181223073942.kiyhjyx3iwa5kvd5@weber> Message-ID: <154560388169.773.14779726368366658444@localhost.localdomain> There are no guarantees about in what order these things will be evaluated. The compiler is well within its rights to evaluate the expressions in any order, or more than once even (though IIRC ghc never does the latter). The left-to-right ordering holds for && because the Haskell report specifically defines[1] it as: True && x = x False && _ = False In this case the compiler can't in general evaluate the RHS first, because if the LHS is False and the RHS is bottom, this would be incorrect. But this is due to the semantics of &&, and doesn't hold in general. -Ian [1]: https://www.haskell.org/onlinereport/haskell2010/haskellch9.html#x16-1710009 Quoting erik (2018-12-23 15:19:04) > Tom, > Why does "b" evaluate before "a" in your example? I would have thought > left-hand and then right-hand if needed. I'm on my phone but I'd like > to try the same example with booleans and `&&` instead of `+`. > Erik > On Sat, Dec 22, 2018, 11:40 PM Tom Ellis > <[1]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk wrote: > > On Sat, Dec 22, 2018 at 09:52:18AM +0100, Damien Mattei wrote: > > i have inserted trace statement that output variable > > ... i have strange behavior of output: > Let's take a simpler example.� Do you understand why the trace > statments > from this small program appear in the order that they do?� (And for > what > it's worth I really think you'll be better off writing programs > using do > notation). > % cat test.hs > import Debug.Trace > result = > � let a = trace "evaluating a" 2 > � � � b = trace "evaluating b" 10 > � � � c = trace "evaluating c" (a + b) > � in c > ~% ghci -e result test.hs > evaluating c > evaluating b > evaluating a > 12 > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > [2]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. > > Verweise > > 1. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > 2. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe From eraker at gmail.com Mon Dec 24 02:52:37 2018 From: eraker at gmail.com (erik) Date: Sun, 23 Dec 2018 18:52:37 -0800 Subject: [Haskell-cafe] trace output statements In-Reply-To: <154560388169.773.14779726368366658444@localhost.localdomain> References: <20181223073942.kiyhjyx3iwa5kvd5@weber> <154560388169.773.14779726368366658444@localhost.localdomain> Message-ID: Ah, I see. I erroneously assumed binary operators would be defined in similar ways but I realize that's perhaps naive because with addition you're never not going to evaluate both sides, unlike with booleans. That's interesting. Thanks for responding. On Sun, Dec 23, 2018, 2:26 PM Ian Denhardt There are no guarantees about in what order these things will be > evaluated. The compiler is well within its rights to evaluate > the expressions in any order, or more than once even (though IIRC > ghc never does the latter). The left-to-right ordering holds for && > because the Haskell report specifically defines[1] it as: > > True && x = x > False && _ = False > > In this case the compiler can't in general evaluate the RHS first, > because if the LHS is False and the RHS is bottom, this would be > incorrect. But this is due to the semantics of &&, and doesn't hold in > general. > > -Ian > > [1]: > https://www.haskell.org/onlinereport/haskell2010/haskellch9.html#x16-1710009 > > Quoting erik (2018-12-23 15:19:04) > > Tom, > > Why does "b" evaluate before "a" in your example? I would have thought > > left-hand and then right-hand if needed. I'm on my phone but I'd like > > to try the same example with booleans and `&&` instead of `+`. > > Erik > > On Sat, Dec 22, 2018, 11:40 PM Tom Ellis > > <[1]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk wrote: > > > > On Sat, Dec 22, 2018 at 09:52:18AM +0100, Damien Mattei wrote: > > > i have inserted trace statement that output variable > > > ... i have strange behavior of output: > > Let's take a simpler example.� Do you understand why the trace > > statments > > from this small program appear in the order that they do?� (And for > > what > > it's worth I really think you'll be better off writing programs > > using do > > notation). > > % cat test.hs > > import Debug.Trace > > result = > > � let a = trace "evaluating a" 2 > > � � � b = trace "evaluating b" 10 > > � � � c = trace "evaluating c" (a + b) > > � in c > > ~% ghci -e result test.hs > > evaluating c > > evaluating b > > evaluating a > > 12 > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > [2]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > > > > Verweise > > > > 1. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > > 2. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: From whosekiteneverfly at gmail.com Mon Dec 24 07:01:41 2018 From: whosekiteneverfly at gmail.com (Yuji Yamamoto) Date: Mon, 24 Dec 2018 16:01:41 +0900 Subject: [Haskell-cafe] Upload new version of indexed-extras or let me take over In-Reply-To: References: Message-ID: Thank you Reiner, and Alexis. But I'm afraid the new version doesn't look uploaded yet... http://hackage.haskell.org/package/indexed-extras If you're okay, I'd like you to add me to the GitHub Project and the maintainer on Hackage. Here're my accounts: http://hackage.haskell.org/user/igrep https://github.com/igrep/ 2018年12月20日(木) 6:49 Reiner Pope : > (haskell-cafe to bcc) > > Hi Yuji, thanks for the ping and sorry for the delay. > > Alexis (cc'd) took over ownership of indexed and indexed-extras at the > beginning of this year, but apparently her permissions to upload packages > to Hackage got reset by a Hackage reset. I've now fixed that, so she can > reupload now (she was generally much more prompt than me). > > I'll upload a new version tonight. > > Not required, but if you like I'm also happy to add you on the GitHub > project and the Hackage packages if you'd like to give me your details. > > Reiner > > On Sat, Dec 15, 2018 at 1:42 AM Yuji Yamamoto > wrote: > >> Hello, this is a reminder of the message I sent (only to Reiner) about >> three weeks ago. >> >> I'm developing some libraries in Haskell with your package indexed-extras >> . >> I found the package can't be built with the latest bifunctor package due >> to its version constraint. >> I sent a pull request >> to fix the problem and it has already been merged. >> Can you release the new version on Hackage? >> It's now the biggest obstacle developing my libraries depending on it. >> >> If you can't maintain the package anymore, I'm willing to take over. >> Thanks in advance. >> >> >> -- >> 山本悠滋 >> twitter: @igrep >> GitHub: https://github.com/igrep >> GitLab: https://gitlab.com/igrep >> Facebook: http://www.facebook.com/igrep >> > -- 山本悠滋 twitter: @igrep GitHub: https://github.com/igrep GitLab: https://gitlab.com/igrep Facebook: http://www.facebook.com/igrep -------------- next part -------------- An HTML attachment was scrubbed... URL: From whosekiteneverfly at gmail.com Mon Dec 24 07:11:46 2018 From: whosekiteneverfly at gmail.com (Yuji Yamamoto) Date: Mon, 24 Dec 2018 16:11:46 +0900 Subject: [Haskell-cafe] Upload new version of indexed-extras or let me take over In-Reply-To: <5c2084edbde8b54426000001@polymail.io> References: <5c2084edbde8b54426000001@polymail.io> Message-ID: Confirmed! Thanks! 2018年12月24日(月) 16:04 Alexis Williams : > It's done. > > Alexis Williams > Sent from Polymail > > > On Sun, Dec 23rd, 2018 at 11:1 PM, Yuji Yamamoto < > whosekiteneverfly at gmail.com> wrote: > >> Thank you Reiner, and Alexis. >> >> But I'm afraid the new version doesn't look uploaded yet... >> http://hackage.haskell.org/package/indexed-extras >> If you're okay, I'd like you to add me to the GitHub Project and the >> maintainer on Hackage. >> Here're my accounts: >> >> http://hackage.haskell.org/user/igrep >> https://github.com/igrep/ >> >> 2018年12月20日(木) 6:49 Reiner Pope : >> >> (haskell-cafe to bcc) >> >> Hi Yuji, thanks for the ping and sorry for the delay. >> >> Alexis (cc'd) took over ownership of indexed and indexed-extras at the >> beginning of this year, but apparently her permissions to upload packages >> to Hackage got reset by a Hackage reset. I've now fixed that, so she can >> reupload now (she was generally much more prompt than me). >> >> I'll upload a new version tonight. >> >> Not required, but if you like I'm also happy to add you on the GitHub >> project and the Hackage packages if you'd like to give me your details. >> >> Reiner >> >> On Sat, Dec 15, 2018 at 1:42 AM Yuji Yamamoto < >> whosekiteneverfly at gmail.com> wrote: >> >> Hello, this is a reminder of the message I sent (only to Reiner) about >> three weeks ago. >> >> I'm developing some libraries in Haskell with your package indexed-extras >> . >> I found the package can't be built with the latest bifunctor package due >> to its version constraint. >> I sent a pull request >> to fix the problem and it has already been merged. >> Can you release the new version on Hackage? >> It's now the biggest obstacle developing my libraries depending on it. >> >> If you can't maintain the package anymore, I'm willing to take over. >> Thanks in advance. >> >> >> -- >> 山本悠滋 >> twitter: @igrep >> GitHub: https://github.com/igrep >> GitLab: https://gitlab.com/igrep >> Facebook: http://www.facebook.com/igrep >> >> >> >> -- >> 山本悠滋 >> twitter: @igrep >> GitHub: https://github.com/igrep >> GitLab: https://gitlab.com/igrep >> Facebook: http://www.facebook.com/igrep >> > > -- 山本悠滋 twitter: @igrep GitHub: https://github.com/igrep GitLab: https://gitlab.com/igrep Facebook: http://www.facebook.com/igrep -------------- next part -------------- An HTML attachment was scrubbed... URL: From b.lijnse at cs.ru.nl Mon Dec 24 08:49:02 2018 From: b.lijnse at cs.ru.nl (Bas Lijnse) Date: Mon, 24 Dec 2018 09:49:02 +0100 Subject: [Haskell-cafe] Reminder Dutch FP-Day 2019 Message-ID: <3c43c957-4940-54b1-479d-f9252bf9ad54@cs.ru.nl> Hi Everybody, Just a quick reminder. You can still register for the "FP Dag" 2019 on January 11 in Breda. The program and additional details are available at https://wiki.clean.cs.ru.nl/NL-FP_dag_2019 Registration closes on January 4. Participation is free, but registration is mandatory. To register simply reply to this e-mail with your name, affiliation (optional) and whether you intend to join us for dinner afterwards. Happy Holidays! Bas and Jan Martin From siddu.druid at gmail.com Mon Dec 24 12:34:04 2018 From: siddu.druid at gmail.com (Siddharth Bhat) Date: Mon, 24 Dec 2018 18:04:04 +0530 Subject: [Haskell-cafe] Places to write and publish projects that "explain ideas"? Message-ID: Hello all, I have somewhat of an unorthodox problem. I've been writing on and off, a series on implementing compilers "beautifully" in haskell, called tiny-optimising-compiler . They're literate haskell files, with the aim of explaining the really elegant ideas that exist in compilers literature - data flow analysis, abstract interpretation, SSA, continuations, scalar evolution, and some more slightly out-there / research-y things, like polyhedral compilation, equality saturation. However, I'm also a research student at my university, and am expected to publish before I graduate. I was looking for possible places to publish a project such as this, whose selling point would be "explains things elegantly, and possibly rewords standard things to nice looking haskell". Are there places where one could conceivably publish about such a project? If not, I forsee myself not being able to finish this project for a while longer, and that would make me sad. Thanks, and a merry christmas to all, ~Siddharth -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Mon Dec 24 13:51:49 2018 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Mon, 24 Dec 2018 20:51:49 +0700 Subject: [Haskell-cafe] Places to write and publish projects that "explain ideas"? In-Reply-To: References: Message-ID: Hi Siddarth, Something implied -- though not explicated -- in your email is that publication serves as some form of requirement before you obtain your degree, yes? So you're looking for places where your articles can gain sufficient endorsement? In that case, you want to find out from your department what kind of publishing standards they demand. Among those who have graduated from your department with publications, precisely where have they published their articles? Best, Kim-Ee On Monday, December 24, 2018, Siddharth Bhat wrote: > Hello all, > > I have somewhat of an unorthodox problem. I've been writing on and off, a > series on implementing compilers > "beautifully" in haskell, called tiny-optimising-compiler > . They're literate > haskell files, with the aim > of explaining the really elegant ideas that exist in compilers literature > - > data flow analysis, abstract interpretation, SSA, continuations, scalar > evolution, > and some more slightly out-there / research-y things, like polyhedral > compilation, equality saturation. > > However, I'm also a research student at my university, and am expected to > publish before I graduate. I was > looking for possible places to publish a project such as this, whose > selling point would be "explains things > elegantly, and possibly rewords standard things to nice looking haskell". > Are there places where one > could conceivably publish about such a project? If not, I forsee myself > not being able to finish this project > for a while longer, and that would make me sad. > > Thanks, and a merry christmas to all, > ~Siddharth > -- -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From mukeshtiwari.iiitm at gmail.com Mon Dec 24 14:32:58 2018 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Tue, 25 Dec 2018 01:32:58 +1100 Subject: [Haskell-cafe] Places to write and publish projects that "explain ideas"? In-Reply-To: References: Message-ID: Hi Siddharth, I am not sure what kind of conference you are looking for, but I found articles published in The Art, Science, and Engineering of Programming [1] pretty neat and interesting. You can have a look, and see if it's fit for your purpose. Best, Mukesh [1] http://programming-journal.org/ On Mon, Dec 24, 2018 at 11:32 PM Siddharth Bhat wrote: > Hello all, > > I have somewhat of an unorthodox problem. I've been writing on and off, a > series on implementing compilers > "beautifully" in haskell, called tiny-optimising-compiler > . They're literate > haskell files, with the aim > of explaining the really elegant ideas that exist in compilers literature > - > data flow analysis, abstract interpretation, SSA, continuations, scalar > evolution, > and some more slightly out-there / research-y things, like polyhedral > compilation, equality saturation. > > However, I'm also a research student at my university, and am expected to > publish before I graduate. I was > looking for possible places to publish a project such as this, whose > selling point would be "explains things > elegantly, and possibly rewords standard things to nice looking haskell". > Are there places where one > could conceivably publish about such a project? If not, I forsee myself > not being able to finish this project > for a while longer, and that would make me sad. > > Thanks, and a merry christmas to all, > ~Siddharth > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From siddu.druid at gmail.com Mon Dec 24 14:50:14 2018 From: siddu.druid at gmail.com (Siddharth Bhat) Date: Mon, 24 Dec 2018 20:20:14 +0530 Subject: [Haskell-cafe] Places to write and publish projects that "explain ideas"? In-Reply-To: References: Message-ID: Hey, yep, indeed, it is considered a requirement. I'm not aware of people in the past who have published articles of this form - in general, the requirements are peer reviewed publications in a "good" journal / conference - measure by impact factor or what have you. Hence the question :) On Mon, 24 Dec, 2018, 19:21 Kim-Ee Yeoh, wrote: > Hi Siddarth, > > Something implied -- though not explicated -- in your email is that > publication serves as some form of requirement before you obtain your > degree, yes? > > So you're looking for places where your articles can gain sufficient > endorsement? > > In that case, you want to find out from your department what kind of > publishing standards they demand. > > Among those who have graduated from your department with publications, > precisely where have they published their articles? > > Best, Kim-Ee > > > On Monday, December 24, 2018, Siddharth Bhat > wrote: > >> Hello all, >> >> I have somewhat of an unorthodox problem. I've been writing on and off, a >> series on implementing compilers >> "beautifully" in haskell, called tiny-optimising-compiler >> . They're literate >> haskell files, with the aim >> of explaining the really elegant ideas that exist in compilers literature >> - >> data flow analysis, abstract interpretation, SSA, continuations, scalar >> evolution, >> and some more slightly out-there / research-y things, like polyhedral >> compilation, equality saturation. >> >> However, I'm also a research student at my university, and am expected to >> publish before I graduate. I was >> looking for possible places to publish a project such as this, whose >> selling point would be "explains things >> elegantly, and possibly rewords standard things to nice looking haskell". >> Are there places where one >> could conceivably publish about such a project? If not, I forsee myself >> not being able to finish this project >> for a while longer, and that would make me sad. >> >> Thanks, and a merry christmas to all, >> ~Siddharth >> > > > -- > -- Kim-Ee > -- Sending this from my phone, please excuse any typos! -------------- next part -------------- An HTML attachment was scrubbed... URL: From kazu at iij.ad.jp Tue Dec 25 05:01:15 2018 From: kazu at iij.ad.jp (Kazu Yamamoto (=?iso-2022-jp?B?GyRCOzNLXE9CSScbKEI=?=)) Date: Tue, 25 Dec 2018 14:01:15 +0900 (JST) Subject: [Haskell-cafe] Happy Haskell Programming for GHC 8.x Message-ID: <20181225.140115.1726010900581011801.kazu@iij.ad.jp> Hello Cafe, I'm happy to announce that Happy Haskell Programming (HHP) version 0.0.0 has been released: http://hackage.haskell.org/package/hhp In short, HHP is a fork from ghc-mod 4.1.6 and re-written for all GHC 8.x. Emacs front end is included. For more information, please read: https://github.com/kazu-yamamoto/hhp Merry Christmas and Happy Haskell Programming on Emacs with GHC 8.x! --Kazu From serg.foo at gmail.com Tue Dec 25 12:20:12 2018 From: serg.foo at gmail.com (Sergey Vinokurov) Date: Tue, 25 Dec 2018 12:20:12 +0000 Subject: [Haskell-cafe] Taking over maintainership of syb Message-ID: <1197e4e8-4b02-eb55-3b86-8eabc1caca87@gmail.com> I'd like to become maintainer of the syb package (http://hackage.haskell.org/package/syb). The current maintainer, José Pedro Magalhães, would like to step down and is looking for anyone interested in picking up the package (https://github.com/dreixel/syb/pull/19). Best regards, Sergey From hcc.olemiss at gmail.com Tue Dec 25 13:32:56 2018 From: hcc.olemiss at gmail.com (Conrad Cunningham) Date: Tue, 25 Dec 2018 07:32:56 -0600 Subject: [Haskell-cafe] Places to write and publish projects that "explain ideas"? In-Reply-To: References: Message-ID: <6D7DD0F9-2011-4F21-B972-78FD3957975B@gmail.com> I have no personal experience with the journal SoftwareX, but one of my department’s undergraduate computer science students published an article with a mathematics professor there. The article included a software component that the CS student did as a part of his senior honors thesis. Sent from my iPhone > On Dec 24, 2018, at 8:50 AM, Siddharth Bhat wrote: > > Hey, yep, indeed, it is considered a requirement. > > > I'm not aware of people in the past who have published articles of this form - in general, the requirements are peer reviewed publications in a "good" journal / conference - measure by impact factor or what have you. Hence the question :) > >> On Mon, 24 Dec, 2018, 19:21 Kim-Ee Yeoh, wrote: >> Hi Siddarth, >> >> Something implied -- though not explicated -- in your email is that publication serves as some form of requirement before you obtain your degree, yes? >> >> So you're looking for places where your articles can gain sufficient endorsement? >> >> In that case, you want to find out from your department what kind of publishing standards they demand. >> >> Among those who have graduated from your department with publications, precisely where have they published their articles? >> >> Best, Kim-Ee >> >> >>> On Monday, December 24, 2018, Siddharth Bhat wrote: >>> Hello all, >>> >>> I have somewhat of an unorthodox problem. I've been writing on and off, a series on implementing compilers >>> "beautifully" in haskell, called tiny-optimising-compiler. They're literate haskell files, with the aim >>> of explaining the really elegant ideas that exist in compilers literature - >>> data flow analysis, abstract interpretation, SSA, continuations, scalar evolution, >>> and some more slightly out-there / research-y things, like polyhedral compilation, equality saturation. >>> >>> However, I'm also a research student at my university, and am expected to publish before I graduate. I was >>> looking for possible places to publish a project such as this, whose selling point would be "explains things >>> elegantly, and possibly rewords standard things to nice looking haskell". Are there places where one >>> could conceivably publish about such a project? If not, I forsee myself not being able to finish this project >>> for a while longer, and that would make me sad. >>> >>> Thanks, and a merry christmas to all, >>> ~Siddharth >> >> >> -- >> -- Kim-Ee > -- > Sending this from my phone, please excuse any typos! > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From siddu.druid at gmail.com Tue Dec 25 14:25:58 2018 From: siddu.druid at gmail.com (Siddharth Bhat) Date: Tue, 25 Dec 2018 19:55:58 +0530 Subject: [Haskell-cafe] Places to write and publish projects that "explain ideas"? In-Reply-To: References: Message-ID: Regarding (1), as far as I'm aware, the requirements are flexible, but the general requirement is "published a paper at a good venue, either journal or conference". This implementation was a hobby project of mine, but I was hoping to be able to justify spending more time on it by finding a venue to publish it at. As for (2), it's mostly expository. The techniques that I am interesting in showing off have no known "simple" implementations as far as I'm aware -- scalar evolution, polyhedral compilation, some kinds of inter-procedural analyses, SSA, etc. do not have simple implementations. Indeed, the goal is to show how to write *optmising* compilers. Most compilers books teach one how to write *a compiler, *while there's a second course usually on compiler optimisation. I don't know of readable, clean implementations of, say, the SSA construction algorithm, or the scalar evolution analysis. Regarding nanopass: I think it makes a lot of sense as a philosophy as a way to architect compilers. However, there are a lot of nice haskell-isms to write compilers which are scattered throughout the literature, as far as I can tell: Hoopl, trees that grow, much of Matt might's work on abstracting abstract interpreters, Scrap-your-boilerplate style techniques, equality saturation, etc. which are all fantastic, but I've never seen them under the same umbrella. So that's a sketch of the general story I want to tell :) Thanks. ~Siddharth On Tue, Dec 25, 2018 at 7:30 PM Richard O'Keefe wrote: > > Question 1: what does your department require? The first person to > consult > is your supervisor. Helping students figure out where to publish is > definitely > part of a supervisor's job (speaking as a former supervisor of PhD > students). > > Question 2: what is the TOPIC of your publication? Since you are merely > (!) > demonstrating known techniques on a toy language, does it really count as > work on compilers? Is it software engineering? Is it computer science > education? Is the aim to develop something more maintainable? What is the > quality metric by which your work should be judged? > > Observation: if you haven't already read the "Nanopass" paper, > https://www.cs.indiana.edu/~dyb/pubs/nano-jfp.pdf , > you should do so now. http://nanopass.org/ is the associated web site. > There is also a mailing list, > https://groups.google.com/forum/#!forum/nanopass-framework > I think your aims are sufficiently close to theirs for you to have > interesting things to say to each other, despite you using Haskell and > them having used Scheme. > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From doug at cs.dartmouth.edu Tue Dec 25 18:19:23 2018 From: doug at cs.dartmouth.edu (Doug McIlroy) Date: Tue, 25 Dec 2018 13:19:23 -0500 Subject: [Haskell-cafe] Places to write and publish projects that 'explain ideas' Message-ID: <201812251819.wBPIJNWu124043@tahoe.cs.Dartmouth.EDU> The project (or an appropriate-sized coherent piece thereof) seems like a good fit for the "programming pearls" department in the Journal of Functional Programming Doug McIlroy From damien.mattei at gmail.com Tue Dec 25 20:07:35 2018 From: damien.mattei at gmail.com (Damien Mattei) Date: Tue, 25 Dec 2018 21:07:35 +0100 Subject: [Haskell-cafe] trace output statements In-Reply-To: <20181223155424.7bhu4fyz7ns47pv4@weber> References: <20181223073942.kiyhjyx3iwa5kvd5@weber> <20181223151128.qcb6b6tnqnhwpktl@weber> <20181223155424.7bhu4fyz7ns47pv4@weber> Message-ID: yes i use do notation, but for example i have code that works in main and not in a function! i print the code perheaps someone could help me: first the function, so you have the import list too: import Database.MySQL.Simple import Database.MySQL.Simple.QueryResults import Database.MySQL.Simple.Result import Database.MySQL.Simple.QueryParams import Database.MySQL.Simple.Param import Control.Monad import Data.Text as Text --import Data.Int as Int --import Data.List import Debug.Trace import Data.Maybe as Maybe -- this function will return th N°BD from Sidonie for a given name -- note: names have been standardized between Sidonie and WDS getBD3 :: Connection -> String -> Float getBD3 conn name = do let qry_head_BD_Sidonie = "select `N° BD` from Coordonnées where Nom = ?" :: Query (bd_rows :: [Only Text]) <- query conn qry_head_BD_Sidonie (Only (name::String)) let noBDtxt = fromOnly (Prelude.head bd_rows) :: Text let noBDstr = Text.unpack noBDtxt :: String let noBDfp = read $ noBDstr :: Float return noBDfp with this function i have this error: Prelude> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:54:13: error: • Couldn't match expected type ‘Float’ with actual type ‘IO Float’ • In a stmt of a 'do' block: (bd_rows :: [Only Text]) <- query conn qry_head_BD_Sidonie (Only (name :: String)) In the expression: do let qry_head_BD_Sidonie = ... (bd_rows :: [Only Text]) <- query conn qry_head_BD_Sidonie (Only (name :: String)) let noBDtxt = ... let noBDstr = ... .... In an equation for ‘getBD3’: getBD3 conn name = do let qry_head_BD_Sidonie = ... (bd_rows :: [Only Text]) <- query conn qry_head_BD_Sidonie (Only (name :: String)) let noBDtxt = ... .... | 54 | (bd_rows :: [Only Text]) <- query conn qry_head_BD_Sidonie (Only (name::String)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Failed, no modules loaded. i do not understand the error complaining that i return an IO float,because i'm sure it's a float in noBDfp if i put the same lines of code in the main it works !!! : main :: IO () main = do conn <- connect defaultConnectInfo { connectHost = "moita", connectUser = "mattei", connectPassword = "sidonie2", connectDatabase = "sidonie" } let qry_head_BD_Sidonie = "select `N° BD` from Coordonnées where Nom = ?" :: Query (bd_rows :: [Only Text]) <- query conn qry_head_BD_Sidonie (Only (name::String)) putStr "bd_rows =" putStrLn $ show bd_rows let noBDtxt = fromOnly (Prelude.head bd_rows) :: Text let noBDstr = Text.unpack noBDtxt :: String let noBDfp = read $ noBDstr :: Float putStr "noBDfp =" (putStrLn (show noBDfp)) close conn it works i have output like this: *Main> main bd_rows =[Only {fromOnly = "-04.3982"}] noBDtxt ="-04.3982" noBDfp =-4.3982 noBDfp + 1 = -3.3982 i'm well getting a float in noBDfp , i even can add 1 to it :-) ( cool haskell...) but i'm just wanting to that in the function getDB3 but it does not compile... ?????? Damien On Sun, Dec 23, 2018 at 4:54 PM Tom Ellis < tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > I think forgetting about monads and just using do-notation will help you. > > On Sun, Dec 23, 2018 at 04:44:57PM +0100, Damien Mattei wrote: > > i think learning Monads from scratch again will help me > > > > On Sun, Dec 23, 2018 at 4:11 PM Tom Ellis < > > tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > > > > > Yes, exactly! > > > > > > On Sun, Dec 23, 2018 at 02:08:57PM +0100, Damien Mattei wrote: > > > > lazyness....? > > > > > > > > On Sun, Dec 23, 2018 at 8:40 AM Tom Ellis < > > > > tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > > > > > > > > > On Sat, Dec 22, 2018 at 09:52:18AM +0100, Damien Mattei wrote: > > > > > > i have inserted trace statement that output variable > > > > > > ... i have strange behavior of output: > > > > > > > > > > Let's take a simpler example. Do you understand why the trace > > > statments > > > > > from this small program appear in the order that they do? (And for > > > what > > > > > it's worth I really think you'll be better off writing programs > using > > > do > > > > > notation). > > > > > > > > > > > > > > > % cat test.hs > > > > > import Debug.Trace > > > > > > > > > > result = > > > > > let a = trace "evaluating a" 2 > > > > > b = trace "evaluating b" 10 > > > > > c = trace "evaluating c" (a + b) > > > > > in c > > > > > ~% ghci -e result test.hs > > > > > evaluating c > > > > > evaluating b > > > > > evaluating a > > > > > 12 > > > _______________________________________________ > > > Haskell-Cafe mailing list > > > To (un)subscribe, modify options or view archives go to: > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > > Only members subscribed via the mailman list are allowed to post. > > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian at zenhack.net Tue Dec 25 21:17:27 2018 From: ian at zenhack.net (Ian Denhardt) Date: Tue, 25 Dec 2018 16:17:27 -0500 Subject: [Haskell-cafe] trace output statements In-Reply-To: References: <20181223073942.kiyhjyx3iwa5kvd5@weber> <20181223151128.qcb6b6tnqnhwpktl@weber> <20181223155424.7bhu4fyz7ns47pv4@weber> Message-ID: <154577264766.1453.9466617599608780706@localhost.localdomain> The correct type annotation for getDB3 should be: getDB3 :: Connection -> String -> IO Float Note the IO at the end. Functions in Haskell are just pure computation; they can't have side effects -- so a function returning a Float can't possibly talk to a database. Instead, The type `IO a` represents a description of an action to perform. It's still just a value -- calling getDB3 doesn't *do* anything. You can stitch these together using do-notation or functions like >>=, and when the program is run the action defined by 'main' is performed. --- An analogy: you could imagine instead of IO we could give up, and write code that computes a program in some other (imperative) programming language) that we then hand off to an interpreter. For example, we could compute a python program that counts from 1 to 99 like so: printNum :: Int -> String printNum n = "print('" ++ show n ++ "')\n" pythonProgram = concatMap printNum [1..99] So we've defined a variable fullProgram that is a string with the source code to a python program like: print('1') print('2') print('3') ... print('99') ..but we haven't actually run it. To do that we'd have to pass the string off to the python interpreter. This is a good way to think about what IO is -- main is like our pythonProgram above, in that it is a description of actions to perform, but *evaluating* it doesn't have any side effects -- it just computes the description. When you run a Haskell program, this is like taking the description defined by Main and passing it off to an interpreter. --- So your definition of getDB3 is a description of actions to perform to get a float from the database, but your type declaration says it's a function that computes a float (without having to perform any "actions"). This is a critical distinction that exists in Haskell but not most other languages. Hope this helps, -Ian Quoting Damien Mattei (2018-12-25 15:07:35) > yes i use do notation, but for example i have code that works in main > and not in a function! > i print the code perheaps someone could help me: > first the function, so you have the import list too: > import Database.MySQL.Simple > import Database.MySQL.Simple.QueryResults > import Database.MySQL.Simple.Result > import Database.MySQL.Simple.QueryParams > import Database.MySQL.Simple.Param > import Control.Monad > import Data.Text as Text > --import Data.Int as Int > --import Data.List > import Debug.Trace > import Data.Maybe as Maybe > -- this function will return th N°BD from Sidonie for a given name > -- note: names have been standardized between Sidonie and WDS > getBD3 :: Connection -> String -> Float > getBD3 conn name = do > � � � � � � � � � � � let qry_head_BD_Sidonie = "select `N° BD` from > Coordonnées where Nom = ?" :: Query > � � � � � � � � � � � (bd_rows :: [Only Text]) <- query conn > qry_head_BD_Sidonie (Only (name::String)) > � � � � � � � � � � � let noBDtxt = fromOnly (Prelude.head bd_rows) :: > Text > � � � � � � � � � � � let noBDstr = Text.unpack noBDtxt :: String > � � � � � � � � � � � let noBDfp = read $ noBDstr :: Float > � � � � � � � � � � � return noBDfp > with this function i have this error: > Prelude> :load UpdateSidonie > [1 of 1] Compiling Main� � � � � � � � � � � � ( UpdateSidonie.hs, > interpreted ) > UpdateSidonie.hs:54:13: error: > � � � � Couldn't match expected type �Float� with actual type �IO > Float� > � � � � In a stmt of a 'do' block: > � � � � � � � (bd_rows :: [Only Text]) <- query > � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � > � conn qry_head_BD_Sidonie (Only (name :: String)) > � � � � � In the expression: > � � � � � � � do let qry_head_BD_Sidonie = ... > � � � � � � � � � � (bd_rows :: [Only Text]) <- query > � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � > � � � � conn qry_head_BD_Sidonie (Only (name :: String)) > � � � � � � � � � � let noBDtxt = ... > � � � � � � � � � � let noBDstr = ... > � � � � � � � � � � .... > � � � � � In an equation for �getBD3�: > � � � � � � � � � getBD3 conn name > � � � � � � � � � � � = do let qry_head_BD_Sidonie = ... > � � � � � � � � � � � � � � � � (bd_rows :: [Only Text]) <- query > � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � > � � � � � � � � � � conn qry_head_BD_Sidonie (Only (name :: String)) > � � � � � � � � � � � � � � � � let noBDtxt = ... > � � � � � � � � � � � � � � � � .... > � � | > 54 |� � � � � � � � � � � � (bd_rows :: [Only Text]) <- query conn > qry_head_BD_Sidonie (Only (name::String)) > � � |� � � � � � � � � � � � > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > ^^^^^^^^^ > Failed, no modules loaded. > i do not understand the error complaining that i return an IO > float,because i'm sure it's a float in noBDfp > if i put the same lines of code in the main it works !!! : > main :: IO () > main = > � do > � � � conn <- connect defaultConnectInfo > � � � � � { connectHost = "moita", > � � � � � � � connectUser = "mattei", > � � � � � � � connectPassword = "sidonie2", > � � � � � � � connectDatabase = "sidonie" } > � let qry_head_BD_Sidonie = "select `N° BD` from Coordonnées where > Nom = ?" :: Query > � (bd_rows :: [Only Text]) <- query conn qry_head_BD_Sidonie (Only > (name::String)) > putStr "bd_rows =" > putStrLn $ show bd_rows > � � � let noBDtxt = fromOnly (Prelude.head bd_rows) :: Text > � � � let noBDstr = Text.unpack noBDtxt :: String > � � � let noBDfp = read $ noBDstr :: Float > � � � putStr "noBDfp =" > � � � (putStrLn (show noBDfp)) > � close conn > it works i have output like this: > *Main> main > bd_rows =[Only {fromOnly = "-04.3982"}] > noBDtxt ="-04.3982" > noBDfp =-4.3982 > noBDfp + 1 = -3.3982 > i'm well getting a float in noBDfp , i even can add 1 to it :-) ( cool > haskell...) > but i'm just wanting to that in the function getDB3 but it does not > compile... > ?????? > Damien > > On Sun, Dec 23, 2018 at 4:54 PM Tom Ellis > <[1]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > > I think forgetting about monads and just using do-notation will help > you. > On Sun, Dec 23, 2018 at 04:44:57PM +0100, Damien Mattei wrote: > > i think learning Monads from scratch again will help me > > > > On Sun, Dec 23, 2018 at 4:11 PM Tom Ellis < > > [2]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > > > > > Yes, exactly! > > > > > > On Sun, Dec 23, 2018 at 02:08:57PM +0100, Damien Mattei wrote: > > > > lazyness....? > > > > > > > > On Sun, Dec 23, 2018 at 8:40 AM Tom Ellis < > > > > [3]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > > > > > > > > > On Sat, Dec 22, 2018 at 09:52:18AM +0100, Damien Mattei > wrote: > > > > > > i have inserted trace statement that output variable > > > > > > ... i have strange behavior of output: > > > > > > > > > > Let's take a simpler example.� Do you understand why the > trace > > > statments > > > > > from this small program appear in the order that they do?� > (And for > > > what > > > > > it's worth I really think you'll be better off writing > programs using > > > do > > > > > notation). > > > > > > > > > > > > > > > % cat test.hs > > > > > import Debug.Trace > > > > > > > > > > result = > > > > >� � let a = trace "evaluating a" 2 > > > > >� � � � b = trace "evaluating b" 10 > > > > >� � � � c = trace "evaluating c" (a + b) > > > > >� � in c > > > > > ~% ghci -e result test.hs > > > > > evaluating c > > > > > evaluating b > > > > > evaluating a > > > > > 12 > > > _______________________________________________ > > > Haskell-Cafe mailing list > > > To (un)subscribe, modify options or view archives go to: > > > [4]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > > Only members subscribed via the mailman list are allowed to > post. > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > [5]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > [6]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. > > Verweise > > 1. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > 2. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > 3. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > 4. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > 5. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > 6. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe From matthewtpickering at gmail.com Tue Dec 25 21:34:07 2018 From: matthewtpickering at gmail.com (Matthew Pickering) Date: Tue, 25 Dec 2018 21:34:07 +0000 Subject: [Haskell-cafe] Taking over maintainership of syb In-Reply-To: <1197e4e8-4b02-eb55-3b86-8eabc1caca87@gmail.com> References: <1197e4e8-4b02-eb55-3b86-8eabc1caca87@gmail.com> Message-ID: What are your intentions as maintainer of the package? I would rather that any maintainer does not modify the API of the package in any significant way. There are other better generics libraries which are more performant and more expressive which have surpassed syb. On Tue, Dec 25, 2018 at 12:20 PM Sergey Vinokurov wrote: > > I'd like to become maintainer of the syb package > (http://hackage.haskell.org/package/syb). The current maintainer, José > Pedro Magalhães, would like to step down and is looking for anyone > interested in picking up the package > (https://github.com/dreixel/syb/pull/19). > > Best regards, > Sergey > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. From ian at zenhack.net Tue Dec 25 22:16:39 2018 From: ian at zenhack.net (Ian Denhardt) Date: Tue, 25 Dec 2018 17:16:39 -0500 Subject: [Haskell-cafe] trace output statements In-Reply-To: References: <20181223073942.kiyhjyx3iwa5kvd5@weber> <20181223151128.qcb6b6tnqnhwpktl@weber> <20181223155424.7bhu4fyz7ns47pv4@weber> <154577264766.1453.9466617599608780706@localhost.localdomain> Message-ID: <154577619921.4977.5744723228015880075@localhost.localdomain> (Adding the list back to Cc; you forgot to hit reply all) Quoting Damien Mattei (2018-12-25 16:57:04) > i get in trouble understanding what fmap was doing, fmap (for IO) just applies a function to the result of the action, so: fmap f action is equivalent to: do result <- action return (f result) > and why the same thing to do in main and in a function had so > different implementations... I suspect the modified version of the program has some differences that aren't strictly necessary just to factor out the relevant bits into their own definition; this *shouldn't* be major surgery. Hard for me to point out without having the two full examples handy. Quoting Damien Mattei (2018-12-25 16:57:04) > yes, i understand with your python example, it's like read on a web > page, IO are not a "cake" but IO are "a recipe for the cake"... > functions are pure in haskell, so they can not have side effects... > what put me some trouble is an answer 2 weeks ago, someone gave me > hints that lead to this solution for getDB: > getBD :: Connection -> String -> IO Float > getBD conn name = trace "Entering getBD" noBDfp > � where qry_head_BD_Sidonie = "select `N° BD` from Coordonnées where > Nom = ?" :: Query > � � � � � � � bd_rows :: IO [Only Text] > � � � � � � � bd_rows = query conn qry_head_BD_Sidonie (Only > (name::String)) > � � � � � � � noBDtxt :: IO Text > � � � � � � � noBDtxt = trace "assigning noBDtxt" (fmap (fromOnly . > Prelude.head) bd_rows) > � � � � � � � noBDstr :: IO String > � � � � � � � noBDstr = trace "assigning noBDstr" (fmap Text.unpack > noBDtxt) > � � � � � � � noBDfp :: IO Float > � � � � � � � noBDfp = fmap read noBDstr > which was code different from the code in main,i get in trouble > understanding what fmap was doing , and why the same thing to do in > main and in a function had so different implementations... > > On Tue, Dec 25, 2018 at 10:19 PM Ian Denhardt <[1]ian at zenhack.net> > wrote: > > The correct type annotation for getDB3 should be: > � � getDB3 :: Connection -> String -> IO Float > Note the IO at the end. Functions in Haskell are just pure > computation; > they can't have side effects -- so a function returning a Float > can't > possibly talk to a database. > Instead, The type `IO a` represents a description of an action to > perform.� It's still just a value -- calling getDB3 doesn't *do* > anything. You can stitch these together using do-notation or > functions > like >>=, and when the program is run the action defined by 'main' > is > performed. > --- > An analogy: you could imagine instead of IO we could give up, and > write > code that computes a program in some other (imperative) programming > language) that we then hand off to an interpreter. For example, we > could > compute a python program that counts from 1 to 99 like so: > � � printNum :: Int -> String > � � printNum n = "print('" ++ show n ++ "')\n" > � � pythonProgram = concatMap printNum [1..99] > So we've defined a variable fullProgram that is a string with the > source > code to a python program like: > � � print('1') > � � print('2') > � � print('3') > � � ... > � � print('99') > ..but we haven't actually run it. To do that we'd have to pass the > string off to the python interpreter. > This is a good way to think about what IO is -- main is like our > pythonProgram above, in that it is a description of actions to > perform, > but *evaluating* it doesn't have any side effects -- it just > computes > the description. When you run a Haskell program, this is like taking > the description defined by Main and passing it off to an > interpreter. > --- > So your definition of getDB3 is a description of actions to perform > to > get a float from the database, but your type declaration says it's a > function that computes a float (without having to perform any > "actions"). > This is a critical distinction that exists in Haskell but not most > other > languages. > Hope this helps, > -Ian > Quoting Damien Mattei (2018-12-25 15:07:35) > >� � yes i use do notation, but for example i have code that works > in main > >� � and not in a function! > >� � i print the code perheaps someone could help me: > >� � first the function, so you have the import list too: > >� � import Database.MySQL.Simple > >� � import Database.MySQL.Simple.QueryResults > >� � import Database.MySQL.Simple.Result > >� � import Database.MySQL.Simple.QueryParams > >� � import Database.MySQL.Simple.Param > >� � import Control.Monad > >� � import Data.Text as Text > >� � --import Data.Int as Int > >� � --import Data.List > >� � import Debug.Trace > >� � import Data.Maybe as Maybe > >� � -- this function will return th N°BD from Sidonie for a > given name > >� � -- note: names have been standardized between Sidonie and WDS > >� � getBD3 :: Connection -> String -> Float > >� � getBD3 conn name = do > >� � � � � � � � � � � � �� let > qry_head_BD_Sidonie = "select `N° BD` from > >� � Coordonnées where Nom = ?" :: Query > >� � � � � � � � � � � � �� (bd_rows :: > [Only Text]) <- query conn > >� � qry_head_BD_Sidonie (Only (name::String)) > >� � � � � � � � � � � � �� let noBDtxt = > fromOnly (Prelude.head bd_rows) :: > >� � Text > >� � � � � � � � � � � � �� let noBDstr = > Text.unpack noBDtxt :: String > >� � � � � � � � � � � � �� let noBDfp = > read $ noBDstr :: Float > >� � � � � � � � � � � � �� return noBDfp > >� � with this function i have this error: > >� � Prelude> :load UpdateSidonie > >� � [1 of 1] Compiling Main� � � � � � � � � > � � �� ( UpdateSidonie.hs, > >� � interpreted ) > >� � UpdateSidonie.hs:54:13: error: > >� � � � �� � Couldn't match expected type �Float� > with actual type �IO > >� � Float� > >� � � � �� � In a stmt of a 'do' block: > >� � � � � � � � �� (bd_rows :: [Only Text]) <- > query > >� � � � � � � � � � � � � � � � � > � � � � � � � � � � � � � � � � � > � � � � > >� � � �� conn qry_head_BD_Sidonie (Only (name :: String)) > >� � � � � � �� In the expression: > >� � � � � � � � �� do let qry_head_BD_Sidonie = > ... > >� � � � � � � � � � � �� (bd_rows :: [Only > Text]) <- query > >� � � � � � � � � � � � � � � � � > � � � � � � � � � � � � � � � � � > � � � � > >� � � � � � �� conn qry_head_BD_Sidonie (Only (name :: > String)) > >� � � � � � � � � � � �� let noBDtxt = ... > >� � � � � � � � � � � �� let noBDstr = ... > >� � � � � � � � � � � �� .... > >� � � � � � �� In an equation for �getBD3�: > >� � � � � � � � � � �� getBD3 conn name > >� � � � � � � � � � � � �� = do let > qry_head_BD_Sidonie = ... > >� � � � � � � � � � � � � � � � � > �� (bd_rows :: [Only Text]) <- query > >� � � � � � � � � � � � � � � � � > � � � � � � � � � � � � � � � � � > � � � � > >� � � � � � � � � � � � �� conn > qry_head_BD_Sidonie (Only (name :: String)) > >� � � � � � � � � � � � � � � � � > �� let noBDtxt = ... > >� � � � � � � � � � � � � � � � � > �� .... > >� � � �� | > >� � 54 |� � � � � � � � � � � �� > (bd_rows :: [Only Text]) <- query conn > >� � qry_head_BD_Sidonie (Only (name::String)) > >� � � �� |� � � � � � � � � � � � > >� � > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > ^^^ > >� � ^^^^^^^^^ > >� � Failed, no modules loaded. > >� � i do not understand the error complaining that i return an IO > >� � float,because i'm sure it's a float in noBDfp > >� � if i put the same lines of code in the main it works !!! : > >� � main :: IO () > >� � main = > >� � �� do > >� � � � �� conn <- connect defaultConnectInfo > >� � � � � � �� { connectHost = "moita", > >� � � � � � � � �� connectUser = "mattei", > >� � � � � � � � �� connectPassword = "sidonie2", > >� � � � � � � � �� connectDatabase = "sidonie" } > >� � � let qry_head_BD_Sidonie = "select `N° BD` from > Coordonnées where > >� � Nom = ?" :: Query > >� � � (bd_rows :: [Only Text]) <- query conn > qry_head_BD_Sidonie (Only > >� � (name::String)) > >� � putStr "bd_rows =" > >� � putStrLn $ show bd_rows > >� � � � �� let noBDtxt = fromOnly (Prelude.head bd_rows) > :: Text > >� � � � �� let noBDstr = Text.unpack noBDtxt :: String > >� � � � �� let noBDfp = read $ noBDstr :: Float > >� � � � �� putStr "noBDfp =" > >� � � � �� (putStrLn (show noBDfp)) > >� � � close conn > >� � it works i have output like this: > >� � *Main> main > >� � bd_rows =[Only {fromOnly = "-04.3982"}] > >� � noBDtxt ="-04.3982" > >� � noBDfp =-4.3982 > >� � noBDfp + 1 = -3.3982 > >� � i'm well getting a float in noBDfp , i even can add 1 to it > :-) ( cool > >� � haskell...) > >� � but i'm just wanting to that in the function getDB3 but it > does not > >� � compile... > >� � ?????? > >� � Damien > > > >� � On Sun, Dec 23, 2018 at 4:54 PM Tom Ellis > >� � <[1][2]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > > > >� � � I think forgetting about monads and just using do-notation > will help > >� � � you. > >� � � On Sun, Dec 23, 2018 at 04:44:57PM +0100, Damien Mattei > wrote: > >� � � > i think learning Monads from scratch again will help me > >� � � > > >� � � > On Sun, Dec 23, 2018 at 4:11 PM Tom Ellis < > >� � � > [2][3]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> > wrote: > >� � � > > >� � � > > Yes, exactly! > >� � � > > > >� � � > > On Sun, Dec 23, 2018 at 02:08:57PM +0100, Damien > Mattei wrote: > >� � � > > > lazyness....? > >� � � > > > > >� � � > > > On Sun, Dec 23, 2018 at 8:40 AM Tom Ellis < > >� � � > > > [3][4]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> > wrote: > >� � � > > > > >� � � > > > > On Sat, Dec 22, 2018 at 09:52:18AM +0100, Damien > Mattei > >� � � wrote: > >� � � > > > > > i have inserted trace statement that output > variable > >� � � > > > > > ... i have strange behavior of output: > >� � � > > > > > >� � � > > > > Let's take a simpler example.�� Do you > understand why the > >� � � trace > >� � � > > statments > >� � � > > > > from this small program appear in the order that > they do?� > >� � � (And for > >� � � > > what > >� � � > > > > it's worth I really think you'll be better off > writing > >� � � programs using > >� � � > > do > >� � � > > > > notation). > >� � � > > > > > >� � � > > > > > >� � � > > > > % cat test.hs > >� � � > > > > import Debug.Trace > >� � � > > > > > >� � � > > > > result = > >� � � > > > >�� � let a = trace "evaluating a" 2 > >� � � > > > >�� �� �� � b = trace "evaluating b" 10 > >� � � > > > >�� �� �� � c = trace "evaluating c" (a + > b) > >� � � > > > >�� � in c > >� � � > > > > ~% ghci -e result test.hs > >� � � > > > > evaluating c > >� � � > > > > evaluating b > >� � � > > > > evaluating a > >� � � > > > > 12 > >� � � > > _______________________________________________ > >� � � > > Haskell-Cafe mailing list > >� � � > > To (un)subscribe, modify options or view archives go > to: > >� � � > > > [4][5]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > >� � � > > Only members subscribed via the mailman list are > allowed to > >� � � post. > >� � � > _______________________________________________ > >� � � > Haskell-Cafe mailing list > >� � � > To (un)subscribe, modify options or view archives go to: > >� � � > > [5][6]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > >� � � > Only members subscribed via the mailman list are allowed > to post. > >� � � _______________________________________________ > >� � � Haskell-Cafe mailing list > >� � � To (un)subscribe, modify options or view archives go to: > >� � � > [6][7]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > >� � � Only members subscribed via the mailman list are allowed > to post. > > > > Verweise > > > >� � 1. mailto:[8]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > >� � 2. mailto:[9]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > >� � 3. mailto:[10]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > >� � 4. > [11]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > >� � 5. > [12]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > >� � 6. > [13]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Verweise > > 1. mailto:ian at zenhack.net > 2. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > 3. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > 4. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > 5. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > 6. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > 7. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > 8. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > 9. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > 10. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > 11. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > 12. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > 13. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe From schernichkin at gmail.com Tue Dec 25 23:04:47 2018 From: schernichkin at gmail.com (=?UTF-8?B?0KHRgtCw0L3QuNGB0LvQsNCyINCn0LXRgNC90LjRh9C60LjQvQ==?=) Date: Wed, 26 Dec 2018 02:04:47 +0300 Subject: [Haskell-cafe] MVar considered harmful In-Reply-To: <154525768780.3676.10247480171207787756@localhost.localdomain> References: <154525768780.3676.10247480171207787756@localhost.localdomain> Message-ID: >IIRC, MVars (in Haskell anyway) also have some fairness guarantees, which I don't see otherwise mentioned in the discussion so far. Looking at given mutex implementation I guess fairness controlled by the primitive itself. More particular: 1. Each thread which trying to obtain mutex will wait for one I-Var exclusively (no competing threads waits shared I-Var hence there is no space for “unfair” schedule). 2. I-Var’s swapped by atomic ‘getAndSet’ which is likely can be implemented over CAS or LL/SC and will be as fair as hardware could be. > If the goal is to have a simpler base primitive on which to build, everything has to boil down to compare-and-swap, load-linked/store-conditional, etc I had this discussion with a Cats guys, but I still can’t understand how it’s possible to implement generic non-busy waiting with CAS/LL-SC only. Ok, somewhere at deeper level it’s actually CAS/LL-SC, but one of the threads should be able to HLT (privileged instruction). Otherwise non-busy waiting would not be possible. Speaking other words, generic locking strategy should allow you to deadlock. How would you implement non-busy deadlock without HLT? Probably I’m missing something, and I’ll be grateful if anyone clarifies. Because I was told multiple times that CAS/LL-SC is enough along, but I can’t figure out myself. > If what you're after is *composable* concurrency, simpler locks won't get you that. Composability is not a point at all currently. I’m not after composability I’m after completeness. Let me speculate a bit and presume that any sufficiently complex composable system (i.e. such a system which would hold some “correctness” properties over allowed composition operations) will necessary be incomplete (i.e. some “correct” expressions will be inexpressible due to the lack of compositions rules and there is no way to supplement the system without making it controversial). This is my very personal interpretation of the Godel Theorem and pure speculation, but look, every non-Turing complete language will prohibit correct programs, on the other hand, every Turing complete will allow you to write non-terminating programs (contradictions). I believe, same property holds with concurrency. If some system prohibits you from deadlocks, it will also prohibit you from some correct synchronization strategies (once again, it’s my speculations, maybe there is a proof of contrary, but I haven't found them yet). Standing from this point, it’s worth to have some complete and controversial (uncomposable) API at low level and having several composable implementations over it with their restrictions. >async exceptions, you're in the same situation with MVars as you are with all resource-acquiring IO actions in Haskell. In my opinion they are completely different. In one case we should provide guaranteed resource release, so we want to make resource acquisition atomic. In other case we want to make wait operation interruptible (hence – non-atomic unless acquisition consists of only one operation). Consider `mask $ \restore -> do { x <- resourceAcquisition; interruptibleOperation; onException (restore $ f x) (resorceRelease<1> x); resorceRelease<2> x }`. In case of interruption we will neither get to resorceRelease<1> nor to resorceRelease<2> (that is why uninterruptibleMask was introduced). Its tempting to consider a MVar as a resource, but resources don’t like interruptions, they should be separated. чт, 20 дек. 2018 г. в 01:16, Ian Denhardt : > A few thoughts: > > * IIRC, MVars (in Haskell anyway) also have some fairness guarantees, > which I don't see otherwise mentioned in the discussion so far. > Compare to STM, where large transactions are susceptible to > starvation. > * If the goal is to have a simpler base primitive on which to build, > everything has to boil down to compare-and-swap, > load-linked/store-conditional, etc -- whatever the machine provides. > When you start talking about even mutexes and semaphores, you're > already dealing with higher-level abstractions, so the thinking about > what's the right "primitive" seems silly to me at that point; you > should be thinking about what the high-level (user) code should be > able to do, and then figure out how to meet in the middle. > * If what you're after is *composable* concurrency, simpler locks won't > get you that. STM is the best general solution I've seen for this, and > if you're doing concurrency stuff in Haskell, I would say use STM > unless you have a specific reason to do something else. > * Re: async exceptions, you're in the same situation with MVars as you > are with all resource-acquiring IO actions in Haskell. `withMVar` and > friends cover async-exception safety, and you can't get rid of mask and > friends by swapping out MVars with another primitive anyway, because > you still need them for acquiring other (non-concurrency related) > resources, like files. > > -Ian > -- Sincerely, Stanislav Chernichkin. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian at zenhack.net Wed Dec 26 01:28:04 2018 From: ian at zenhack.net (Ian Denhardt) Date: Tue, 25 Dec 2018 20:28:04 -0500 Subject: [Haskell-cafe] MVar considered harmful In-Reply-To: References: <154525768780.3676.10247480171207787756@localhost.localdomain> Message-ID: <154578768399.9339.9918251220198714571@localhost.localdomain> Quoting Станислав Черничкин (2018-12-25 18:04:47) > >IIRC, MVars (in Haskell anyway) also have some fairness guarantees, > which I don't see otherwise mentioned in the discussion so far. > Looking at given mutex implementation I guess fairness controlled by > the primitive itself. More particular:� > 1. Each thread which trying to obtain mutex will wait for one I-Var > exclusively (no competing threads waits shared I-Var hence there is no > space for �unfair� schedule). > 2. I-Var�s swapped by atomic �getAndSet� which is likely can be > implemented over CAS or LL/SC and will be as fair as hardware could > be.� > > If the goal is to have a simpler base primitive on which to build, > everything has to boil down to compare-and-swap, > load-linked/store-conditional, etc > I had this discussion with a Cats guys, but I still can�t understand > how it�s possible to implement generic non-busy waiting with CAS/LL-SC > only. Ok, somewhere at deeper level it�s actually CAS/LL-SC, > HLT (privileged instruction). Right, so you have to build on primitives exposed by the OS instead. If you've got userspace threads you can "block" by scheduling another thread, if you have one, but indeed you can't not burn cpu cycles without the OS. > Standing from this point, it�s worth to have some complete and > controversial (uncomposable) API at low level and having several > composable implementations over it with their restrictions. How low level are we talking? My first instinct would be "just expose whatever the OS and machine give you." > (hence non-atomic unless acquisition consists of only one operation). But takeMVar *is* only one operation. I'm not following the distinction? -Ian From jo at durchholz.org Wed Dec 26 07:33:23 2018 From: jo at durchholz.org (Joachim Durchholz) Date: Wed, 26 Dec 2018 08:33:23 +0100 Subject: [Haskell-cafe] MVar considered harmful In-Reply-To: References: <154525768780.3676.10247480171207787756@localhost.localdomain> Message-ID: <4189079a-f3be-91da-2f13-25723090d70d@durchholz.org> Am 26.12.18 um 00:04 schrieb Станислав Черничкин: > Ok, somewhere at deeper level it’s actually CAS/LL-SC, but one of the > threads should be able to HLT (privileged instruction). Otherwise > non-busy waiting would not be possible. HLT stops the entire processor, including operating system. No way a user process should ever execute *that*. What actually happens is that threads are simply not scheduled, with strongly implementation-dependent means of making them runnable again (some schedulers require that you state runnability upfront, in the form of a mutex, futex, semaphore, monitor, or whatever; others allow one thread to change the runnability of another thread post-hoc). > Composability is not a point at all currently. I’m not after > composability I’m after completeness. Let me speculate a bit and presume > that any sufficiently complex composable system (i.e. such a system > which would hold some “correctness” properties over allowed composition > operations) will necessary be incomplete (i.e. some “correct” > expressions will be inexpressible due to the lack of compositions rules > and there is no way to supplement the system without making it > controversial). > > This is my very personal interpretation of the Godel Theorem and pure > speculation, The computer science equivalent of the Godel Theorem is "undecidability". That's well-trodden ground. In practice, the options are: 1. Giving up correctness is not very useful. (There are extremely rare exceptions - be prepared to strongly defend any a suggestion of that kind.) 2. Giving up completeness can still be useful. You do not get true universality, but you get a correctness guarantee. 3. You can still have both correctness and completeness. If your heuristics are good, you'll get a result in the vast majority of cases in practice. The cases that don't work out will simply run into an endless loop; just add a timeout to the computation. Obviously, you don't want such an approach for time-critical stuff like thread scheduling, but it's been used successfully e.g. for type systems that are more powerful than Hindley-Milner. 4. Do not solve the problem at all. E.g. don't prevent deadlocks by inspecting code and determining whether it can deadlock or not; detect deadlocks after they happen and report them as errors. > but look, every non-Turing complete language will prohibit > correct programs, on the other hand, every Turing complete will allow > you to write non-terminating programs (contradictions). I believe, same > property holds with concurrency. You get into undecidability issues at the point where an algorithm needs to analyze a program for termination. So people have been using algorithms don't inspect programs, but which inspect data (Haskell's infinite data structures would be categorized as program in this discussion, because it's code that will return finite portions of the infinite data structure). Even with finite data, algorithms can be undecidable. It's rare and usually doesn't happen, but it can happen if the data structure somehow expresses a Turing-complete language. Note that compilers and such never actually analyze the full program, they just apply patterns that a programmer has decided preserve semantics. (Mistakes here usually lead to compiler bugs.) > If some system prohibits you from > deadlocks, it will also prohibit you from some correct synchronization > strategies (once again, it’s my speculations, maybe there is a proof of > contrary, but I haven't found them yet). Correct, but this is only a problem in practice if you need a locking scheme that can express undecidable locking strategies. I am not a grand master of locking strategies, but I see locking strategies move from semaphores (undecidable) towards higher-level constructs that do not allow all kinds of locking anymore. I don't think that futures etc. exclude deadlocks by construction, but I do see that deadlocks have become a less common problem. > Standing from this point, it’s worth to have some complete and > controversial (uncomposable) API at low level and having several > composable implementations over it with their restrictions. That's one of today's difficult goals: Designing a locking API that's both composable and useful. I'm not sure whether such a thing has even been thought of yet. From m at jaspervdj.be Wed Dec 26 12:06:57 2018 From: m at jaspervdj.be (Jasper Van der Jeugt) Date: Wed, 26 Dec 2018 13:06:57 +0100 Subject: [Haskell-cafe] ZuriHac 2019 registration now open Message-ID: <20181226120657.GA12504@colony6.localdomain> Hello Friends of Haskell, We are happy to announce that registration for ZuriHac 2019 is now open. Participation is free but limited to 450 attendees. You can register at: https://zfoh.ch/zurihac2019/#registration This year, we've taken dogfooding a step further and rolled our own open source registration system in Haskell, so please let me know if you experience any issues. ZuriHac 2019 will take place from Friday the 14th to Sunday the 16th of June 2019. It will be hosted at the Hochschule Rapperswil on the shores of beautiful Lake Zurich. This will mark the 8th anniversary of ZuriHac since our beginnings in 2010. The Zurich Haskell Hackathon is a free, international, grassroots, and collaborative coding festival. Our goal is to connect Haskellers, expand the community, learn things from each other, and to work on Haskell libraries, tools, and infrastructure. This year, we will enjoy keynotes from: - Simon Peyton Jones - Susan Potter - Richard Eisenberg - Ryan Trinkle More keynote speakers will be announced. The event is open to any experience level, from beginners to gurus. We want to make a special effort to ensure that the event is welcoming and accessible to people completely new to Haskell. That is why we are super excited that, Julie Moronuki, co-author of Haskell Programming from first principles [1] and Joy of Haskell [2], has kindly agreed to teach a beginners course in one of the classrooms we have available. Additionally, there will be mentors that you can approach during the whole event with any Haskell-related questions. This is a great opportunity to meet your fellow Haskellers in real life, find new contributors for your project, improve existing libraries and tools or even start new ones! You can find all of this information and more on our website: https://zfoh.ch/zurihac2019 We would also like to thank our sponsors Digital Asset [3], DFINITY [4] and HSR [5] for their strong commitment to the Haskell community and for supporting this great event! Looking forward to seeing you there, The Zurich Friends of Haskell association. [1]: https://www.goodreads.com/book/show/25587599-haskell-programming [2]: https://joyofhaskell.com/ [3]: https://digitalasset.com/careers.html [4]: https://dfinity.org/jobs [5]: https://www.hsr.ch/ From vanessa.mchale at iohk.io Wed Dec 26 14:56:53 2018 From: vanessa.mchale at iohk.io (Vanessa McHale) Date: Wed, 26 Dec 2018 08:56:53 -0600 Subject: [Haskell-cafe] Poor performance when using hsc2hs to cross-compile Message-ID: <8d69ff9e-9838-03f2-4018-b92258470224@iohk.io> Hi all, I've been trying to cross-compile X11 for ARM. Unfortunately, the build runs in the preprocessor phase for a very very long time when preprocessing Graphics/X11/Types.hsc Upon passing -v to hsc2hs I saw many steps like     checking XK_abrevebelowdot `GreaterOrEqual` Unsigned 17039360         executing: /usr/bin/arm-linux-gnueabihf-gcc -c /home/vanessa/git-builds/junk/X11-1.9/dist-newstyle/build/arm-linux/ghc-8.6.3/X11-1.9/build/Graphics/X11/ExtraTypes/XorgDefault_hsc_test37988.c -o /home/vanessa/git-builds/junk/X11-1.9/dist-newstyle/build/arm-linux/ghc-8.6.3/X11-1.9/build/Graphics/X11/ExtraTypes/XorgDefault_hsc_test37988.o -marm -fno-stack-protector '-fuse-ld=gold' -Wl,-z,noexecstack '-D__GLASGOW_HASKELL__=806' '-Dlinux_BUILD_OS=1' '-Dx86_64_BUILD_ARCH=1' '-Dlinux_HOST_OS=1' '-Darm_HOST_ARCH=1' -Iinclude -I/home/vanessa/git-builds/junk/X11-1.9/dist-newstyle/build/arm-linux/ghc-8.6.3/X11-1.9/build/include -I/home/vanessa/git-builds/junk/X11-1.9/dist-newstyle/build/arm-linux/ghc-8.6.3/X11-1.9/build/autogen -I/home/vanessa/git-builds/junk/X11-1.9/dist-newstyle/build/arm-linux/ghc-8.6.3/X11-1.9/build/global-autogen -include /home/vanessa/git-builds/junk/X11-1.9/dist-newstyle/build/arm-linux/ghc-8.6.3/X11-1.9/build/autogen/cabal_macros.h -I/usr/local/lib/arm-linux-gnueabihf-ghc-8.6.3/base-4.12.0.0/include -I/usr/local/lib/arm-linux-gnueabihf-ghc-8.6.3/integer-gmp-1.0.2.0/include -I/usr/local/lib/arm-linux-gnueabihf-ghc-8.6.3/include         result: False which I assume are necessary or at least progressing... Is there any way to speed this up? Is it a bug of some sort in hsc2hs or X11? Is there any hope in reporting upstream to the appropriate project (and what is the appropriate project in this case?)? Cheers, Vanessa -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From damien.mattei at gmail.com Wed Dec 26 22:24:53 2018 From: damien.mattei at gmail.com (Damien Mattei) Date: Wed, 26 Dec 2018 23:24:53 +0100 Subject: [Haskell-cafe] trace output statements In-Reply-To: <154577619921.4977.5744723228015880075@localhost.localdomain> References: <20181223073942.kiyhjyx3iwa5kvd5@weber> <20181223151128.qcb6b6tnqnhwpktl@weber> <20181223155424.7bhu4fyz7ns47pv4@weber> <154577264766.1453.9466617599608780706@localhost.localdomain> <154577619921.4977.5744723228015880075@localhost.localdomain> Message-ID: i'm learning fmap, but for now i want to convert the previous function: getBD :: Connection -> String -> IO Float getBD conn name = do let qry_head_BD_Sidonie = "select `N° BD` from Coordonnées where Nom = ?" :: Query (bd_rows :: [Only Text]) <- query conn qry_head_BD_Sidonie (Only (name::String)) let noBDtxt = fromOnly (Prelude.head bd_rows) :: Text let noBDstr = Text.unpack noBDtxt :: String let noBDfp = read $ noBDstr :: Float return noBDfp that works but fails in case of NULL in database, i want the code to works also with NULL, detecting them with Nothing, and short circuit them with Maybe or something else, so i change the function definition to this type and here is the whole code: getBD2 :: Connection -> String -> IO (Maybe Float) getBD2 conn name = do let qry_head_BD_Sidonie = "select `N° BD` from Coordonnées where Nom = ?" :: Query (bd_rows :: [Only (Maybe Text)]) <- query conn qry_head_BD_Sidonie (Only (name::String)) let noBDtxt = if (isNothing (fromOnly (Prelude.head bd_rows))) then (return Nothing) else (fromOnly (Prelude.head bd_rows) :: Maybe Text) let noBDstr = Text.unpack noBDtxt :: Maybe String let noBDfp = read $ noBDstr :: Maybe Float return noBDfp unfortunately it fails to compile, something is wrong here: Prelude Data.Maybe> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:68:33: error: • Couldn't match type ‘Text’ with ‘Maybe a’ Expected type: Maybe (Maybe a) Actual type: Maybe Text • In the expression: (fromOnly (Prelude.head bd_rows) :: Maybe Text) In the expression: if (isNothing (fromOnly (Prelude.head bd_rows))) then (return Nothing) else (fromOnly (Prelude.head bd_rows) :: Maybe Text) In an equation for ‘noBDtxt’: noBDtxt = if (isNothing (fromOnly (Prelude.head bd_rows))) then (return Nothing) else (fromOnly (Prelude.head bd_rows) :: Maybe Text) • Relevant bindings include noBDtxt :: Maybe (Maybe a) (bound at UpdateSidonie.hs:66:17) | 68 | else (fromOnly (Prelude.head bd_rows) :: Maybe Text) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UpdateSidonie.hs:69:27: error: • Couldn't match type ‘[Char]’ with ‘Maybe String’ Expected type: Maybe String Actual type: String • In the expression: unpack noBDtxt :: Maybe String In an equation for ‘noBDstr’: noBDstr = unpack noBDtxt :: Maybe String In the expression: do let qry_head_BD_Sidonie = ... (bd_rows :: [Only (Maybe Text)]) <- query conn qry_head_BD_Sidonie (Only (name :: String)) let noBDtxt = ... let noBDstr = ... .... | 69 | let noBDstr = Text.unpack noBDtxt :: Maybe String | ^^^^^^^^^^^^^^^^^^^ UpdateSidonie.hs:69:39: error: • Couldn't match expected type ‘Text’ with actual type ‘Maybe (Maybe a0)’ • In the first argument of ‘unpack’, namely ‘noBDtxt’ In the expression: unpack noBDtxt :: Maybe String In an equation for ‘noBDstr’: noBDstr = unpack noBDtxt :: Maybe String | 69 | let noBDstr = Text.unpack noBDtxt :: Maybe String | ^^^^^^^ UpdateSidonie.hs:70:33: error: • Couldn't match type ‘Maybe String’ with ‘[Char]’ Expected type: String Actual type: Maybe String • In the second argument of ‘($)’, namely ‘noBDstr’ In the expression: read $ noBDstr :: Maybe Float In an equation for ‘noBDfp’: noBDfp = read $ noBDstr :: Maybe Float | 70 | let noBDfp = read $ noBDstr :: Maybe Float | ^^^^^^^ Failed, no modules loaded. what is the solution? it will help me in my project and to understand Haskell way of handling null objects. Damien On Tue, Dec 25, 2018 at 11:18 PM Ian Denhardt wrote: > > (Adding the list back to Cc; you forgot to hit reply all) > > Quoting Damien Mattei (2018-12-25 16:57:04) > > > i get in trouble understanding what fmap was doing, > > fmap (for IO) just applies a function to the result of the action, so: > > fmap f action > > is equivalent to: > > do > result <- action > return (f result) > > > and why the same thing to do in main and in a function had so > > different implementations... > > I suspect the modified version of the program has some differences that > aren't strictly necessary just to factor out the relevant bits into > their own definition; this *shouldn't* be major surgery. Hard for me to > point out without having the two full examples handy. > > Quoting Damien Mattei (2018-12-25 16:57:04) > > yes, i understand with your python example, it's like read on a web > > page, IO are not a "cake" but IO are "a recipe for the cake"... > > functions are pure in haskell, so they can not have side effects... > > what put me some trouble is an answer 2 weeks ago, someone gave me > > hints that lead to this solution for getDB: > > getBD :: Connection -> String -> IO Float > > getBD conn name = trace "Entering getBD" noBDfp > > � where qry_head_BD_Sidonie = "select `N° BD` from Coordonnées where > > Nom = ?" :: Query > > � � � � � � � bd_rows :: IO [Only Text] > > � � � � � � � bd_rows = query conn qry_head_BD_Sidonie (Only > > (name::String)) > > � � � � � � � noBDtxt :: IO Text > > � � � � � � � noBDtxt = trace "assigning noBDtxt" (fmap (fromOnly . > > Prelude.head) bd_rows) > > � � � � � � � noBDstr :: IO String > > � � � � � � � noBDstr = trace "assigning noBDstr" (fmap Text.unpack > > noBDtxt) > > � � � � � � � noBDfp :: IO Float > > � � � � � � � noBDfp = fmap read noBDstr > > which was code different from the code in main,i get in trouble > > understanding what fmap was doing , and why the same thing to do in > > main and in a function had so different implementations... > > > > On Tue, Dec 25, 2018 at 10:19 PM Ian Denhardt <[1]ian at zenhack.net> > > wrote: > > > > The correct type annotation for getDB3 should be: > > � � getDB3 :: Connection -> String -> IO Float > > Note the IO at the end. Functions in Haskell are just pure > > computation; > > they can't have side effects -- so a function returning a Float > > can't > > possibly talk to a database. > > Instead, The type `IO a` represents a description of an action to > > perform.� It's still just a value -- calling getDB3 doesn't *do* > > anything. You can stitch these together using do-notation or > > functions > > like >>=, and when the program is run the action defined by 'main' > > is > > performed. > > --- > > An analogy: you could imagine instead of IO we could give up, and > > write > > code that computes a program in some other (imperative) programming > > language) that we then hand off to an interpreter. For example, we > > could > > compute a python program that counts from 1 to 99 like so: > > � � printNum :: Int -> String > > � � printNum n = "print('" ++ show n ++ "')\n" > > � � pythonProgram = concatMap printNum [1..99] > > So we've defined a variable fullProgram that is a string with the > > source > > code to a python program like: > > � � print('1') > > � � print('2') > > � � print('3') > > � � ... > > � � print('99') > > ..but we haven't actually run it. To do that we'd have to pass the > > string off to the python interpreter. > > This is a good way to think about what IO is -- main is like our > > pythonProgram above, in that it is a description of actions to > > perform, > > but *evaluating* it doesn't have any side effects -- it just > > computes > > the description. When you run a Haskell program, this is like taking > > the description defined by Main and passing it off to an > > interpreter. > > --- > > So your definition of getDB3 is a description of actions to perform > > to > > get a float from the database, but your type declaration says it's a > > function that computes a float (without having to perform any > > "actions"). > > This is a critical distinction that exists in Haskell but not most > > other > > languages. > > Hope this helps, > > -Ian > > Quoting Damien Mattei (2018-12-25 15:07:35) > > >� � yes i use do notation, but for example i have code that works > > in main > > >� � and not in a function! > > >� � i print the code perheaps someone could help me: > > >� � first the function, so you have the import list too: > > >� � import Database.MySQL.Simple > > >� � import Database.MySQL.Simple.QueryResults > > >� � import Database.MySQL.Simple.Result > > >� � import Database.MySQL.Simple.QueryParams > > >� � import Database.MySQL.Simple.Param > > >� � import Control.Monad > > >� � import Data.Text as Text > > >� � --import Data.Int as Int > > >� � --import Data.List > > >� � import Debug.Trace > > >� � import Data.Maybe as Maybe > > >� � -- this function will return th N°BD from Sidonie for a > > given name > > >� � -- note: names have been standardized between Sidonie and WDS > > >� � getBD3 :: Connection -> String -> Float > > >� � getBD3 conn name = do > > >� � � � � � � � � � � � �� let > > qry_head_BD_Sidonie = "select `N° BD` from > > >� � Coordonnées where Nom = ?" :: Query > > >� � � � � � � � � � � � �� (bd_rows :: > > [Only Text]) <- query conn > > >� � qry_head_BD_Sidonie (Only (name::String)) > > >� � � � � � � � � � � � �� let noBDtxt = > > fromOnly (Prelude.head bd_rows) :: > > >� � Text > > >� � � � � � � � � � � � �� let noBDstr = > > Text.unpack noBDtxt :: String > > >� � � � � � � � � � � � �� let noBDfp = > > read $ noBDstr :: Float > > >� � � � � � � � � � � � �� return noBDfp > > >� � with this function i have this error: > > >� � Prelude> :load UpdateSidonie > > >� � [1 of 1] Compiling Main� � � � � � � � � > > � � �� ( UpdateSidonie.hs, > > >� � interpreted ) > > >� � UpdateSidonie.hs:54:13: error: > > >� � � � �� � Couldn't match expected type �Float� > > with actual type �IO > > >� � Float� > > >� � � � �� � In a stmt of a 'do' block: > > >� � � � � � � � �� (bd_rows :: [Only Text]) <- > > query > > >� � � � � � � � � � � � � � � � � > > � � � � � � � � � � � � � � � � � > > � � � � > > >� � � �� conn qry_head_BD_Sidonie (Only (name :: String)) > > >� � � � � � �� In the expression: > > >� � � � � � � � �� do let qry_head_BD_Sidonie = > > ... > > >� � � � � � � � � � � �� (bd_rows :: [Only > > Text]) <- query > > >� � � � � � � � � � � � � � � � � > > � � � � � � � � � � � � � � � � � > > � � � � > > >� � � � � � �� conn qry_head_BD_Sidonie (Only (name :: > > String)) > > >� � � � � � � � � � � �� let noBDtxt = ... > > >� � � � � � � � � � � �� let noBDstr = ... > > >� � � � � � � � � � � �� .... > > >� � � � � � �� In an equation for �getBD3�: > > >� � � � � � � � � � �� getBD3 conn name > > >� � � � � � � � � � � � �� = do let > > qry_head_BD_Sidonie = ... > > >� � � � � � � � � � � � � � � � � > > �� (bd_rows :: [Only Text]) <- query > > >� � � � � � � � � � � � � � � � � > > � � � � � � � � � � � � � � � � � > > � � � � > > >� � � � � � � � � � � � �� conn > > qry_head_BD_Sidonie (Only (name :: String)) > > >� � � � � � � � � � � � � � � � � > > �� let noBDtxt = ... > > >� � � � � � � � � � � � � � � � � > > �� .... > > >� � � �� | > > >� � 54 |� � � � � � � � � � � �� > > (bd_rows :: [Only Text]) <- query conn > > >� � qry_head_BD_Sidonie (Only (name::String)) > > >� � � �� |� � � � � � � � � � � � > > >� � > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > ^^^ > > >� � ^^^^^^^^^ > > >� � Failed, no modules loaded. > > >� � i do not understand the error complaining that i return an IO > > >� � float,because i'm sure it's a float in noBDfp > > >� � if i put the same lines of code in the main it works !!! : > > >� � main :: IO () > > >� � main = > > >� � �� do > > >� � � � �� conn <- connect defaultConnectInfo > > >� � � � � � �� { connectHost = "moita", > > >� � � � � � � � �� connectUser = "mattei", > > >� � � � � � � � �� connectPassword = "sidonie2", > > >� � � � � � � � �� connectDatabase = "sidonie" } > > >� � � let qry_head_BD_Sidonie = "select `N° BD` from > > Coordonnées where > > >� � Nom = ?" :: Query > > >� � � (bd_rows :: [Only Text]) <- query conn > > qry_head_BD_Sidonie (Only > > >� � (name::String)) > > >� � putStr "bd_rows =" > > >� � putStrLn $ show bd_rows > > >� � � � �� let noBDtxt = fromOnly (Prelude.head bd_rows) > > :: Text > > >� � � � �� let noBDstr = Text.unpack noBDtxt :: String > > >� � � � �� let noBDfp = read $ noBDstr :: Float > > >� � � � �� putStr "noBDfp =" > > >� � � � �� (putStrLn (show noBDfp)) > > >� � � close conn > > >� � it works i have output like this: > > >� � *Main> main > > >� � bd_rows =[Only {fromOnly = "-04.3982"}] > > >� � noBDtxt ="-04.3982" > > >� � noBDfp =-4.3982 > > >� � noBDfp + 1 = -3.3982 > > >� � i'm well getting a float in noBDfp , i even can add 1 to it > > :-) ( cool > > >� � haskell...) > > >� � but i'm just wanting to that in the function getDB3 but it > > does not > > >� � compile... > > >� � ?????? > > >� � Damien > > > > > >� � On Sun, Dec 23, 2018 at 4:54 PM Tom Ellis > > >� � <[1][2]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > > > > > >� � � I think forgetting about monads and just using do-notation > > will help > > >� � � you. > > >� � � On Sun, Dec 23, 2018 at 04:44:57PM +0100, Damien Mattei > > wrote: > > >� � � > i think learning Monads from scratch again will help me > > >� � � > > > >� � � > On Sun, Dec 23, 2018 at 4:11 PM Tom Ellis < > > >� � � > [2][3]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> > > wrote: > > >� � � > > > >� � � > > Yes, exactly! > > >� � � > > > > >� � � > > On Sun, Dec 23, 2018 at 02:08:57PM +0100, Damien > > Mattei wrote: > > >� � � > > > lazyness....? > > >� � � > > > > > >� � � > > > On Sun, Dec 23, 2018 at 8:40 AM Tom Ellis < > > >� � � > > > [3][4]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> > > wrote: > > >� � � > > > > > >� � � > > > > On Sat, Dec 22, 2018 at 09:52:18AM +0100, Damien > > Mattei > > >� � � wrote: > > >� � � > > > > > i have inserted trace statement that output > > variable > > >� � � > > > > > ... i have strange behavior of output: > > >� � � > > > > > > >� � � > > > > Let's take a simpler example.�� Do you > > understand why the > > >� � � trace > > >� � � > > statments > > >� � � > > > > from this small program appear in the order that > > they do?� > > >� � � (And for > > >� � � > > what > > >� � � > > > > it's worth I really think you'll be better off > > writing > > >� � � programs using > > >� � � > > do > > >� � � > > > > notation). > > >� � � > > > > > > >� � � > > > > > > >� � � > > > > % cat test.hs > > >� � � > > > > import Debug.Trace > > >� � � > > > > > > >� � � > > > > result = > > >� � � > > > >�� � let a = trace "evaluating a" 2 > > >� � � > > > >�� �� �� � b = trace "evaluating b" 10 > > >� � � > > > >�� �� �� � c = trace "evaluating c" (a + > > b) > > >� � � > > > >�� � in c > > >� � � > > > > ~% ghci -e result test.hs > > >� � � > > > > evaluating c > > >� � � > > > > evaluating b > > >� � � > > > > evaluating a > > >� � � > > > > 12 > > >� � � > > _______________________________________________ > > >� � � > > Haskell-Cafe mailing list > > >� � � > > To (un)subscribe, modify options or view archives go > > to: > > >� � � > > > > [4][5]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > >� � � > > Only members subscribed via the mailman list are > > allowed to > > >� � � post. > > >� � � > _______________________________________________ > > >� � � > Haskell-Cafe mailing list > > >� � � > To (un)subscribe, modify options or view archives go to: > > >� � � > > > [5][6]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > >� � � > Only members subscribed via the mailman list are allowed > > to post. > > >� � � _______________________________________________ > > >� � � Haskell-Cafe mailing list > > >� � � To (un)subscribe, modify options or view archives go to: > > >� � � > > [6][7]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > >� � � Only members subscribed via the mailman list are allowed > > to post. > > > > > > Verweise > > > > > >� � 1. mailto:[8]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > > >� � 2. mailto:[9]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > > >� � 3. mailto:[10]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > > >� � 4. > > [11]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > >� � 5. > > [12]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > >� � 6. > > [13]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > > > Verweise > > > > 1. mailto:ian at zenhack.net > > 2. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > > 3. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > > 4. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > > 5. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > 6. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > 7. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > 8. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > > 9. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > > 10. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk > > 11. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > 12. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > 13. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > -------------- next part -------------- An HTML attachment was scrubbed... URL: From damien.mattei at gmail.com Thu Dec 27 00:03:10 2018 From: damien.mattei at gmail.com (Damien Mattei) Date: Thu, 27 Dec 2018 01:03:10 +0100 Subject: [Haskell-cafe] Handling NULL value , was :trace output statements In-Reply-To: References: <20181223073942.kiyhjyx3iwa5kvd5@weber> <20181223151128.qcb6b6tnqnhwpktl@weber> <20181223155424.7bhu4fyz7ns47pv4@weber> <154577264766.1453.9466617599608780706@localhost.localdomain> <154577619921.4977.5744723228015880075@localhost.localdomain> Message-ID: finally, late in night i got myself a working solution :-) : getBD2 :: Connection -> String -> IO (Maybe Float) getBD2 conn name = do let qry_head_BD_Sidonie = "select `N° BD` from Coordonnées where Nom = ?" :: Query (bd_rows :: [Only (Maybe Text)]) <- query conn qry_head_BD_Sidonie (Only (name::String)) let noBDtxt = fromOnly (Prelude.head bd_rows) :: Maybe Text case noBDtxt of Nothing -> return Nothing Just noBDtxt -> do putStrLn "getBD2" let noBDstr = Text.unpack noBDtxt :: String let noBDfp = readMaybe noBDstr :: Maybe Float return noBDfp note that i had to change read in readMaybe due to Exception: Prelude.read: no parse,solved here (i do not really understand why) : https://stackoverflow.com/questions/27947925/haskell-prelude-read-no-parse-string note also in the last lines i infer a Maybe Float from a NOT maybe String , but the compiler did not notice it.... in my main function i call and display like that:(2 solution due to a Just appearing in terminal...) noBD <- getBD2 conn name putStrLn ("noBD = " ++ (show noBD)) putStrLn $ "noBD = " ++ maybe "NULL" show noBD display like this: getBD2 noBD = Just (-4.3982) noBD = -4.3982 but if someone has a more elegant or concise solution ? .... my opinion: Haskell is weird... :-) On Wed, Dec 26, 2018 at 11:24 PM Damien Mattei wrote: > i'm learning fmap, but for now i want to convert the previous function: > > getBD :: Connection -> String -> IO Float > getBD conn name = do > let qry_head_BD_Sidonie = "select `N° BD` from Coordonnées > where Nom = ?" :: Query > (bd_rows :: [Only Text]) <- query conn qry_head_BD_Sidonie > (Only (name::String)) > let noBDtxt = fromOnly (Prelude.head bd_rows) :: Text > let noBDstr = Text.unpack noBDtxt :: String > let noBDfp = read $ noBDstr :: Float > return noBDfp > > that works but fails in case of NULL in database, > i want the code to works also with NULL, detecting them with Nothing, and > short circuit them with Maybe or something else, so i change the function > definition to this type and here is the whole code: > > getBD2 :: Connection -> String -> IO (Maybe Float) > getBD2 conn name = do > let qry_head_BD_Sidonie = "select `N° BD` from Coordonnées > where Nom = ?" :: Query > (bd_rows :: [Only (Maybe Text)]) <- query conn > qry_head_BD_Sidonie (Only (name::String)) > let noBDtxt = if (isNothing (fromOnly (Prelude.head bd_rows))) > then (return Nothing) > else (fromOnly (Prelude.head bd_rows) :: Maybe > Text) > let noBDstr = Text.unpack noBDtxt :: Maybe String > let noBDfp = read $ noBDstr :: Maybe Float > return noBDfp > > unfortunately it fails to compile, something is wrong here: > > Prelude Data.Maybe> :load UpdateSidonie > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > UpdateSidonie.hs:68:33: error: > • Couldn't match type ‘Text’ with ‘Maybe a’ > Expected type: Maybe (Maybe a) > Actual type: Maybe Text > • In the expression: > (fromOnly (Prelude.head bd_rows) :: Maybe Text) > In the expression: > if (isNothing (fromOnly (Prelude.head bd_rows))) then > (return Nothing) > else > (fromOnly (Prelude.head bd_rows) :: Maybe Text) > In an equation for ‘noBDtxt’: > noBDtxt > = if (isNothing (fromOnly (Prelude.head bd_rows))) then > (return Nothing) > else > (fromOnly (Prelude.head bd_rows) :: Maybe Text) > • Relevant bindings include > noBDtxt :: Maybe (Maybe a) (bound at UpdateSidonie.hs:66:17) > | > 68 | else (fromOnly (Prelude.head bd_rows) :: > Maybe Text) > | > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > UpdateSidonie.hs:69:27: error: > • Couldn't match type ‘[Char]’ with ‘Maybe String’ > Expected type: Maybe String > Actual type: String > • In the expression: unpack noBDtxt :: Maybe String > In an equation for ‘noBDstr’: > noBDstr = unpack noBDtxt :: Maybe String > In the expression: > do let qry_head_BD_Sidonie = ... > (bd_rows :: [Only (Maybe Text)]) <- query > conn qry_head_BD_Sidonie > (Only (name :: String)) > let noBDtxt = ... > let noBDstr = ... > .... > | > 69 | let noBDstr = Text.unpack noBDtxt :: Maybe String > | ^^^^^^^^^^^^^^^^^^^ > > UpdateSidonie.hs:69:39: error: > • Couldn't match expected type ‘Text’ > with actual type ‘Maybe (Maybe a0)’ > • In the first argument of ‘unpack’, namely ‘noBDtxt’ > In the expression: unpack noBDtxt :: Maybe String > In an equation for ‘noBDstr’: > noBDstr = unpack noBDtxt :: Maybe String > | > 69 | let noBDstr = Text.unpack noBDtxt :: Maybe String > | ^^^^^^^ > > UpdateSidonie.hs:70:33: error: > • Couldn't match type ‘Maybe String’ with ‘[Char]’ > Expected type: String > Actual type: Maybe String > • In the second argument of ‘($)’, namely ‘noBDstr’ > In the expression: read $ noBDstr :: Maybe Float > In an equation for ‘noBDfp’: noBDfp = read $ noBDstr :: Maybe Float > | > 70 | let noBDfp = read $ noBDstr :: Maybe Float > | ^^^^^^^ > Failed, no modules loaded. > > what is the solution? it will help me in my project and to understand > Haskell way of handling null objects. > > Damien > > > On Tue, Dec 25, 2018 at 11:18 PM Ian Denhardt wrote: > >> >> (Adding the list back to Cc; you forgot to hit reply all) >> >> Quoting Damien Mattei (2018-12-25 16:57:04) >> >> > i get in trouble understanding what fmap was doing, >> >> fmap (for IO) just applies a function to the result of the action, so: >> >> fmap f action >> >> is equivalent to: >> >> do >> result <- action >> return (f result) >> >> > and why the same thing to do in main and in a function had so >> > different implementations... >> >> I suspect the modified version of the program has some differences that >> aren't strictly necessary just to factor out the relevant bits into >> their own definition; this *shouldn't* be major surgery. Hard for me to >> point out without having the two full examples handy. >> >> Quoting Damien Mattei (2018-12-25 16:57:04) >> > yes, i understand with your python example, it's like read on a web >> > page, IO are not a "cake" but IO are "a recipe for the cake"... >> > functions are pure in haskell, so they can not have side effects... >> > what put me some trouble is an answer 2 weeks ago, someone gave me >> > hints that lead to this solution for getDB: >> > getBD :: Connection -> String -> IO Float >> > getBD conn name = trace "Entering getBD" noBDfp >> > � where qry_head_BD_Sidonie = "select `N° BD` from Coordonnées where >> > Nom = ?" :: Query >> > � � � � � � � bd_rows :: IO [Only Text] >> > � � � � � � � bd_rows = query conn qry_head_BD_Sidonie (Only >> > (name::String)) >> > � � � � � � � noBDtxt :: IO Text >> > � � � � � � � noBDtxt = trace "assigning noBDtxt" (fmap (fromOnly . >> > Prelude.head) bd_rows) >> > � � � � � � � noBDstr :: IO String >> > � � � � � � � noBDstr = trace "assigning noBDstr" (fmap Text.unpack >> > noBDtxt) >> > � � � � � � � noBDfp :: IO Float >> > � � � � � � � noBDfp = fmap read noBDstr >> > which was code different from the code in main,i get in trouble >> > understanding what fmap was doing , and why the same thing to do in >> > main and in a function had so different implementations... >> > >> > On Tue, Dec 25, 2018 at 10:19 PM Ian Denhardt <[1]ian at zenhack.net> >> > wrote: >> > >> > The correct type annotation for getDB3 should be: >> > � � getDB3 :: Connection -> String -> IO Float >> > Note the IO at the end. Functions in Haskell are just pure >> > computation; >> > they can't have side effects -- so a function returning a Float >> > can't >> > possibly talk to a database. >> > Instead, The type `IO a` represents a description of an action to >> > perform.� It's still just a value -- calling getDB3 doesn't *do* >> > anything. You can stitch these together using do-notation or >> > functions >> > like >>=, and when the program is run the action defined by 'main' >> > is >> > performed. >> > --- >> > An analogy: you could imagine instead of IO we could give up, and >> > write >> > code that computes a program in some other (imperative) programming >> > language) that we then hand off to an interpreter. For example, we >> > could >> > compute a python program that counts from 1 to 99 like so: >> > � � printNum :: Int -> String >> > � � printNum n = "print('" ++ show n ++ "')\n" >> > � � pythonProgram = concatMap printNum [1..99] >> > So we've defined a variable fullProgram that is a string with the >> > source >> > code to a python program like: >> > � � print('1') >> > � � print('2') >> > � � print('3') >> > � � ... >> > � � print('99') >> > ..but we haven't actually run it. To do that we'd have to pass the >> > string off to the python interpreter. >> > This is a good way to think about what IO is -- main is like our >> > pythonProgram above, in that it is a description of actions to >> > perform, >> > but *evaluating* it doesn't have any side effects -- it just >> > computes >> > the description. When you run a Haskell program, this is like >> taking >> > the description defined by Main and passing it off to an >> > interpreter. >> > --- >> > So your definition of getDB3 is a description of actions to perform >> > to >> > get a float from the database, but your type declaration says it's >> a >> > function that computes a float (without having to perform any >> > "actions"). >> > This is a critical distinction that exists in Haskell but not most >> > other >> > languages. >> > Hope this helps, >> > -Ian >> > Quoting Damien Mattei (2018-12-25 15:07:35) >> > >� � yes i use do notation, but for example i have code that >> works >> > in main >> > >� � and not in a function! >> > >� � i print the code perheaps someone could help me: >> > >� � first the function, so you have the import list too: >> > >� � import Database.MySQL.Simple >> > >� � import Database.MySQL.Simple.QueryResults >> > >� � import Database.MySQL.Simple.Result >> > >� � import Database.MySQL.Simple.QueryParams >> > >� � import Database.MySQL.Simple.Param >> > >� � import Control.Monad >> > >� � import Data.Text as Text >> > >� � --import Data.Int as Int >> > >� � --import Data.List >> > >� � import Debug.Trace >> > >� � import Data.Maybe as Maybe >> > >� � -- this function will return th N°BD from Sidonie for a >> > given name >> > >� � -- note: names have been standardized between Sidonie and >> WDS >> > >� � getBD3 :: Connection -> String -> Float >> > >� � getBD3 conn name = do >> > >� � � � � � � � � � � � �� let >> > qry_head_BD_Sidonie = "select `N° BD` from >> > >� � Coordonnées where Nom = ?" :: Query >> > >� � � � � � � � � � � � �� (bd_rows :: >> > [Only Text]) <- query conn >> > >� � qry_head_BD_Sidonie (Only (name::String)) >> > >� � � � � � � � � � � � �� let noBDtxt = >> > fromOnly (Prelude.head bd_rows) :: >> > >� � Text >> > >� � � � � � � � � � � � �� let noBDstr = >> > Text.unpack noBDtxt :: String >> > >� � � � � � � � � � � � �� let noBDfp = >> > read $ noBDstr :: Float >> > >� � � � � � � � � � � � �� return noBDfp >> > >� � with this function i have this error: >> > >� � Prelude> :load UpdateSidonie >> > >� � [1 of 1] Compiling Main� � � � � � � � � >> > � � �� ( UpdateSidonie.hs, >> > >� � interpreted ) >> > >� � UpdateSidonie.hs:54:13: error: >> > >� � � � �� � Couldn't match expected type �Float� >> > with actual type �IO >> > >� � Float� >> > >� � � � �� � In a stmt of a 'do' block: >> > >� � � � � � � � �� (bd_rows :: [Only Text]) <- >> > query >> > >� � � � � � � � � � � � � � � � � >> > � � � � � � � � � � � � � � � � � >> > � � � � >> > >� � � �� conn qry_head_BD_Sidonie (Only (name :: String)) >> > >� � � � � � �� In the expression: >> > >� � � � � � � � �� do let qry_head_BD_Sidonie = >> > ... >> > >� � � � � � � � � � � �� (bd_rows :: [Only >> > Text]) <- query >> > >� � � � � � � � � � � � � � � � � >> > � � � � � � � � � � � � � � � � � >> > � � � � >> > >� � � � � � �� conn qry_head_BD_Sidonie (Only (name :: >> > String)) >> > >� � � � � � � � � � � �� let noBDtxt = ... >> > >� � � � � � � � � � � �� let noBDstr = ... >> > >� � � � � � � � � � � �� .... >> > >� � � � � � �� In an equation for �getBD3�: >> > >� � � � � � � � � � �� getBD3 conn name >> > >� � � � � � � � � � � � �� = do let >> > qry_head_BD_Sidonie = ... >> > >� � � � � � � � � � � � � � � � � >> > �� (bd_rows :: [Only Text]) <- query >> > >� � � � � � � � � � � � � � � � � >> > � � � � � � � � � � � � � � � � � >> > � � � � >> > >� � � � � � � � � � � � �� conn >> > qry_head_BD_Sidonie (Only (name :: String)) >> > >� � � � � � � � � � � � � � � � � >> > �� let noBDtxt = ... >> > >� � � � � � � � � � � � � � � � � >> > �� .... >> > >� � � �� | >> > >� � 54 |� � � � � � � � � � � �� >> > (bd_rows :: [Only Text]) <- query conn >> > >� � qry_head_BD_Sidonie (Only (name::String)) >> > >� � � �� |� � � � � � � � � � � � >> > >� � >> > >> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >> > ^^^ >> > >� � ^^^^^^^^^ >> > >� � Failed, no modules loaded. >> > >� � i do not understand the error complaining that i return an >> IO >> > >� � float,because i'm sure it's a float in noBDfp >> > >� � if i put the same lines of code in the main it works !!! : >> > >� � main :: IO () >> > >� � main = >> > >� � �� do >> > >� � � � �� conn <- connect defaultConnectInfo >> > >� � � � � � �� { connectHost = "moita", >> > >� � � � � � � � �� connectUser = "mattei", >> > >� � � � � � � � �� connectPassword = "sidonie2", >> > >� � � � � � � � �� connectDatabase = "sidonie" } >> > >� � � let qry_head_BD_Sidonie = "select `N° BD` from >> > Coordonnées where >> > >� � Nom = ?" :: Query >> > >� � � (bd_rows :: [Only Text]) <- query conn >> > qry_head_BD_Sidonie (Only >> > >� � (name::String)) >> > >� � putStr "bd_rows =" >> > >� � putStrLn $ show bd_rows >> > >� � � � �� let noBDtxt = fromOnly (Prelude.head bd_rows) >> > :: Text >> > >� � � � �� let noBDstr = Text.unpack noBDtxt :: String >> > >� � � � �� let noBDfp = read $ noBDstr :: Float >> > >� � � � �� putStr "noBDfp =" >> > >� � � � �� (putStrLn (show noBDfp)) >> > >� � � close conn >> > >� � it works i have output like this: >> > >� � *Main> main >> > >� � bd_rows =[Only {fromOnly = "-04.3982"}] >> > >� � noBDtxt ="-04.3982" >> > >� � noBDfp =-4.3982 >> > >� � noBDfp + 1 = -3.3982 >> > >� � i'm well getting a float in noBDfp , i even can add 1 to it >> > :-) ( cool >> > >� � haskell...) >> > >� � but i'm just wanting to that in the function getDB3 but it >> > does not >> > >� � compile... >> > >� � ?????? >> > >� � Damien >> > > >> > >� � On Sun, Dec 23, 2018 at 4:54 PM Tom Ellis >> > >� � <[1][2]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: >> > > >> > >� � � I think forgetting about monads and just using >> do-notation >> > will help >> > >� � � you. >> > >� � � On Sun, Dec 23, 2018 at 04:44:57PM +0100, Damien Mattei >> > wrote: >> > >� � � > i think learning Monads from scratch again will help me >> > >� � � > >> > >� � � > On Sun, Dec 23, 2018 at 4:11 PM Tom Ellis < >> > >� � � > [2][3]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> >> > wrote: >> > >� � � > >> > >� � � > > Yes, exactly! >> > >� � � > > >> > >� � � > > On Sun, Dec 23, 2018 at 02:08:57PM +0100, Damien >> > Mattei wrote: >> > >� � � > > > lazyness....? >> > >� � � > > > >> > >� � � > > > On Sun, Dec 23, 2018 at 8:40 AM Tom Ellis < >> > >� � � > > > [3][4]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> >> > wrote: >> > >� � � > > > >> > >� � � > > > > On Sat, Dec 22, 2018 at 09:52:18AM +0100, Damien >> > Mattei >> > >� � � wrote: >> > >� � � > > > > > i have inserted trace statement that output >> > variable >> > >� � � > > > > > ... i have strange behavior of output: >> > >� � � > > > > >> > >� � � > > > > Let's take a simpler example.�� Do you >> > understand why the >> > >� � � trace >> > >� � � > > statments >> > >� � � > > > > from this small program appear in the order that >> > they do?� >> > >� � � (And for >> > >� � � > > what >> > >� � � > > > > it's worth I really think you'll be better off >> > writing >> > >� � � programs using >> > >� � � > > do >> > >� � � > > > > notation). >> > >� � � > > > > >> > >� � � > > > > >> > >� � � > > > > % cat test.hs >> > >� � � > > > > import Debug.Trace >> > >� � � > > > > >> > >� � � > > > > result = >> > >� � � > > > >�� � let a = trace "evaluating a" 2 >> > >� � � > > > >�� �� �� � b = trace "evaluating b" 10 >> > >� � � > > > >�� �� �� � c = trace "evaluating c" (a + >> > b) >> > >� � � > > > >�� � in c >> > >� � � > > > > ~% ghci -e result test.hs >> > >� � � > > > > evaluating c >> > >� � � > > > > evaluating b >> > >� � � > > > > evaluating a >> > >� � � > > > > 12 >> > >� � � > > _______________________________________________ >> > >� � � > > Haskell-Cafe mailing list >> > >� � � > > To (un)subscribe, modify options or view archives go >> > to: >> > >� � � > > >> > [4][5] >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> > >� � � > > Only members subscribed via the mailman list are >> > allowed to >> > >� � � post. >> > >� � � > _______________________________________________ >> > >� � � > Haskell-Cafe mailing list >> > >� � � > To (un)subscribe, modify options or view archives go >> to: >> > >� � � > >> > [5][6] >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> > >� � � > Only members subscribed via the mailman list are >> allowed >> > to post. >> > >� � � _______________________________________________ >> > >� � � Haskell-Cafe mailing list >> > >� � � To (un)subscribe, modify options or view archives go to: >> > >� � � >> > [6][7] >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> > >� � � Only members subscribed via the mailman list are allowed >> > to post. >> > > >> > > Verweise >> > > >> > >� � 1. mailto:[8]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk >> > >� � 2. mailto:[9]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk >> > >� � 3. mailto:[10]tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk >> > >� � 4. >> > [11]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> > >� � 5. >> > [12]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> > >� � 6. >> > [13]http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> > >> > Verweise >> > >> > 1. mailto:ian at zenhack.net >> > 2. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk >> > 3. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk >> > 4. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk >> > 5. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> > 6. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> > 7. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> > 8. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk >> > 9. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk >> > 10. mailto:tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk >> > 11. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> > 12. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> > 13. http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ducis_cn at 126.com Fri Dec 28 08:19:09 2018 From: ducis_cn at 126.com (ducis) Date: Fri, 28 Dec 2018 16:19:09 +0800 (CST) Subject: [Haskell-cafe] Find out which part of code are causing parallelism? In-Reply-To: References: Message-ID: <4e36457.7795.167f3e54c2c.Coremail.ducis_cn@126.com> Hi all, I am working on parallelising some program, however I just found out that without inserting any parallism manually the program is already parallelised, presumably by some of the libraries referenced, as long as I enable -threaded and +RTS -N8. Unfortunately this parallism are actually slowing down my program, probably due to being of too fine granularity. For example, with +RTS -N8 I have 47.03user 38.06system 0:21.68elapsed 392%CPU While with +RTS -N1 I have 16.57user 0.45system 0:17.02elapsed 100%CPU In .prof file I can't find whether a function fired a spark or how much 'system' time a function used. Nor can I find any names of functions/modules browsing through eventlog with ghc-events. Is there a way to find out which functions/modules are causing any parallelism at all? I am also trailing the post with the imports I used in case anyone immediately recognises parallelism by default in the package. import Control.DeepSeq import GHC.Generics (Generic, Generic1) import Text.Parsec import Data.List import Data.Vector.Unboxed(fromList, (!)) import qualified Data.Vector as V import qualified Data.Map as M import qualified Data.Set as S import Data.Char import Control.Applicative((*>),(<*)) import Test.QuickCheck.Monadic import Test.QuickCheck import Control.Monad import Text.Regex import Control.Applicative ((<$>), (<$), (<|>)) import GHC.Read (readLitChar) import Data.Char(isPrint) import Text.ParserCombinators.ReadP import Text.Show.Pretty import Data.Functor import Data.Maybe import System.Environment(getArgs) import Text.Read(readMaybe) import Text.Printf import Data.Dynamic import Debug.Trace import Data.Ratio import qualified Data.DList as D import Control.Monad.Trans.Writer.Strict import Control.Monad.Trans.Class import Data.Typeable(Typeable) import qualified Data.HashMap.Lazy as H Best, ducis -------------- next part -------------- An HTML attachment was scrubbed... URL: From vanessa.mchale at iohk.io Fri Dec 28 10:11:50 2018 From: vanessa.mchale at iohk.io (Vanessa McHale) Date: Fri, 28 Dec 2018 04:11:50 -0600 Subject: [Haskell-cafe] Find out which part of code are causing parallelism? In-Reply-To: <4e36457.7795.167f3e54c2c.Coremail.ducis_cn@126.com> References: <4e36457.7795.167f3e54c2c.Coremail.ducis_cn@126.com> Message-ID: <09287686-d8fb-d54e-d63b-79b8f64d79fe@iohk.io> Does threadscope help? It should be of some use since it is designed for debugging parallel programs. Cheers, Vanessa On 12/28/18 2:19 AM, ducis wrote: > Hi all, > > I am working on parallelising some program, however I just found out > that without inserting any parallism manually > the program is already parallelised, presumably by some of the > libraries referenced, as long as I enable -threaded > and +RTS -N8. > > Unfortunately this parallism are actually slowing down my program, > probably due to being of too fine granularity. > For example, with +RTS -N8 I have    > 47.03user 38.06system 0:21.68elapsed 392%CPU > While with +RTS -N1 I have > 16.57user 0.45system 0:17.02elapsed 100%CPU > > In .prof file I can't find whether a function fired a spark or how > much 'system' time a function used. > Nor can I find any names of functions/modules browsing through > eventlog with ghc-events. > Is there a way to find out which functions/modules are causing any > parallelism at all? > > I am also trailing the post with the imports I used in case anyone > immediately recognises parallelism by default in the package. > import Control.DeepSeq > import GHC.Generics (Generic, Generic1) > import > Text.Parsec                                                                         > > import > Data.List                                                                           > > import Data.Vector.Unboxed(fromList, > (!))                                                  > import qualified Data.Vector as > V                                                          > import qualified Data.Map as > M                                                             > import qualified Data.Set as > S                                                             > import > Data.Char                                                                           > > import > Control.Applicative((*>),(<*))                                                      > > import > Test.QuickCheck.Monadic                                                             > > import > Test.QuickCheck                                                                     > > import > Control.Monad                                                                       > > import Text.Regex                                                   > import Control.Applicative ((<$>), (<$), (<|>))        > import GHC.Read (readLitChar)                          > import Data.Char(isPrint)                              > import > Text.ParserCombinators.ReadP                                             > import > Text.Show.Pretty                                                                    > > import > Data.Functor                                                                        > > import > Data.Maybe                                                                          > > import System.Environment(getArgs) > import > Text.Read(readMaybe)                                                                > > import > Text.Printf                                                                                > > import > Data.Dynamic                                                                        > > import > Debug.Trace                                                                         > > import > Data.Ratio                                                                            > > import qualified Data.DList as > D                                                           > import > Control.Monad.Trans.Writer.Strict                                                              > > import > Control.Monad.Trans.Class                                                           > > import > Data.Typeable(Typeable)                                                             > > import qualified Data.HashMap.Lazy as > H                                               > > Best, > ducis     > > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From franciman12 at gmail.com Fri Dec 28 13:29:50 2018 From: franciman12 at gmail.com (Francesco Magliocca) Date: Fri, 28 Dec 2018 14:29:50 +0100 Subject: [Haskell-cafe] [Haskell][ANN] vabal - the cabal companion Message-ID: Hello, I'm please to announce that vabal 1.2.0 has been released on Hackage: http://hackage.haskell.org/package/vabal vabal is a software that helps you determine the ghc version needed to compile a cabal package. It reads the cabal file and extracts the constraints imposed on the base package. Then it uses ghcup ( https://github.com/haskell/ghcup ) to obtain a compiler version compatible with the constraints (possibly downloading it from the official ghc mirror) and can be combined with cabal to build the project using the obtained ghc compiler. In this way you can treat the `base` package dependency as any other package dependency and don't have to manually deal with different ghc versions anymore. vabal is meant to be used in collaboration with cabal. It leverages cabal's ability to work with multiple ghc versions, and tries to be the least intrusive possible, so that you can keep using your usual workflow, but won't have to worry about `base` package dependency issues, anymore. You can get started here: https://github.com/Franciman/vabal#quick-start For details please refer to: https://github.com/Franciman/vabal#vabal---the-cabal-companion Ideas, suggestions, opinions and pull requests are very welcome! A big thank you goes to all the contributors that helped me with code, suggestions and ideas: https://github.com/Franciman/vabal#contributors -------------- next part -------------- An HTML attachment was scrubbed... URL: From guthrie at mum.edu Fri Dec 28 13:43:00 2018 From: guthrie at mum.edu (Gregory Guthrie) Date: Fri, 28 Dec 2018 13:43:00 +0000 Subject: [Haskell-cafe] hackage.org down? Message-ID: I get a failure response from hackage.org: 502 Bad Gateway nginx/1.10.3 (Ubuntu) -------------- next part -------------- An HTML attachment was scrubbed... URL: From johannes.waldmann at htwk-leipzig.de Fri Dec 28 14:07:32 2018 From: johannes.waldmann at htwk-leipzig.de (Johannes Waldmann) Date: Fri, 28 Dec 2018 15:07:32 +0100 Subject: [Haskell-cafe] Find out which part of code are causing parallelism? Message-ID: <9db3d32f-927f-6a08-5741-0d52b8dc2cd9@htwk-leipzig.de> > however I just found out that without inserting > any parallism manually the program is already parallelised, That's not your program, it's the garbage collector. "By default, all of the capabilities participate in parallel garbage collection." https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/runtime_control.html#rts-options-to-control-the-garbage-collector - J.W. From m at jaspervdj.be Fri Dec 28 14:20:50 2018 From: m at jaspervdj.be (Jasper Van der Jeugt) Date: Fri, 28 Dec 2018 15:20:50 +0100 Subject: [Haskell-cafe] [GSoC 2019] Call for Ideas Message-ID: <20181228142050.GB19905@colony6.localdomain> Google Summer of Code will take place again in 2019, for the 15th year of the program [1]! We are very proud that Haskell.Org has been able to take part every year except for the initial year (2015) and 2016-2017, when we had to resort to running our own program. Last year, we were fortunate enough to join again, and we think the results greatly benefited the Haskell community [2]. We are hoping to do the same for 2019. As far as we know, a really important part of our application to GSoC is the list of ideas we provide. For that, I would like to count on all of you. If you are the maintainer or the user of a Haskell project, and you have an improvement in mind which a student could work on during the summer, please submit an idea here: https://summer.haskell.org/ideas.html For context, Google Summer of Code is a program where Google sponsors students to work on open-source projects during the summer. Haskell.org has taken part in this program from 2006 until 2015, and again in 2018. Many important improvements to the ecosystem have been the direct or indirect result of Google Summer of Code projects, and it has also connected new people with the existing community. Projects should benefit as many people as possible – e.g. an improvement to GHC will benefit more people than an update to a specific library or tool, but both are definitely valid. New libraries and applications written in Haskell, rather than improvements to existing ones, are also accepted. Projects should be concrete and small enough in scope such that they can be finished by a student in three months. Warm regards On behalf of the Haskell.Org committee Jasper Van der Jeugt [1]: https://opensource.googleblog.com/2018/11/google-summer-of-code-15-years-strong.html [2]: https://summer.haskell.org/news/2018-09-01-final-results.html From oleg.grenrus at iki.fi Fri Dec 28 14:40:03 2018 From: oleg.grenrus at iki.fi (Oleg Grenrus) Date: Fri, 28 Dec 2018 16:40:03 +0200 Subject: [Haskell-cafe] hackage.org down? In-Reply-To: References: Message-ID: <0fe280c2-4105-bb1e-83e0-0e72979bdac1@iki.fi> It's back up. It's good to check https://status.haskell.org/ and http://auto-status.haskell.org/ First one (should) have messages about scheduled maintenance etc. E.g. today is visible in https://status.haskell.org/pages/history/537c07b0cf1fad5830000093. The latter is auto-status: when two don't match (i.e. former doesn't explain latter), then you should ping some people :) Anyway, everything works now. Cheers, Oleg. On 28.12.2018 15.43, Gregory Guthrie wrote: > > I get a failure response from hackage.org: > >   > > *502 Bad Gateway* > > nginx/1.10.3 (Ubuntu) > >   > > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From bertram.felgenhauer at googlemail.com Fri Dec 28 17:44:08 2018 From: bertram.felgenhauer at googlemail.com (Bertram Felgenhauer) Date: Fri, 28 Dec 2018 18:44:08 +0100 Subject: [Haskell-cafe] MVar considered harmful In-Reply-To: References: Message-ID: <20181228174408.GI16230@24f89f8c-e6a1-4e75-85ee-bb8a3743bb9f> Станислав Черничкин wrote: > Just look at this beautiful mutex implementation > https://github.com/ovotech/fs2-kafka/blob/master/src/main/scala/fs2/kafka/internal/Synchronized.scala As far as I can see, this only works because Java/Scala don't have (or at least, very strongly discourage) asynchronous exceptions. Here's my attempt to translate the code into Haskell: import Control.Concurrent.MVar -- should be an IVar import Control.Concurrent import Control.Exception (bracket) import Data.IORef type Mutex = IORef (MVar ()) newMutex :: IO Mutex newMutex = do next <- newMVar () newIORef next withMutex :: Mutex -> IO () -> IO () withMutex m act = do next <- newEmptyMVar bracket (atomicModifyIORef m (\curr -> (next, curr))) -- atomic swap (\_ -> putMVar next ()) $ \curr -> do readMVar curr -- readMVar is no longer a combination of takeMVar/putMVar -- since base 4.7, so we can faithfully emulate an IVar act Now if the `readMVar` is interrupted by an asynchronous exception, subsequent threads will be woken up, violating the mutual exclusion property. For example: mkThread lock nm = do tid <- forkIO $ withMutex lock $ do putStrLn $ unwords ["thread", nm, "running"] threadDelay 200000 putStrLn $ unwords ["thread", nm, "stopping"] yield return tid main = do lock <- newMutex threadA <- mkThread lock "A" threadB <- mkThread lock "B" threadC <- mkThread lock "C" killThread threadB threadDelay 1000000 Output: thread A running thread C running thread C stopping thread A stopping Oops. This is awkward to fix. Basically, when abandoning the lock before it has been released by the previous owner, we need a new thread to wait for the 'current' IVar and notify the 'next' one, since the current thread is being interrupted. So `withMutex` will end up with code like this: withMutex :: Mutex -> IO () -> IO () withMutex m act = do next <- newEmptyMVar bracket (atomicModifyIORef m (\curr -> (next, curr))) (cleanup next) $ \curr -> do readMVar curr act where cleanup :: MVar () -> MVar () -> IO () cleanup next curr = do b <- tryReadMVar next case b of Just _ -> putMVar next () Nothing -> void $ forkIO $ do readMVar curr putMVar next () This loses a lot of elegance. On the low-level implementation side, both MVars and IVars need to maintain a list of waiting threads; both require logic to wake up threads (IVars will wake all threads; when putting a value, MVars will wake up threads reading the MVar, up to the first thread (if any) that actually takes the MVar value). I believe MVars are not much more difficult to implement than IVars. (This assumes a global memory; IVars may be simpler in a distributed setting.) For users, MVars are dangerous if used without restrictions, but we have easy to understand patterns, for example for using an MVar as a mutex (newMVar, withMVar), or as an IVar (newEmptyMVar, putMVar, readMVar). To summarize, IVars may be harder to misuse, but MVars provide tangible benefits as a primitive, especially in the presence of asynchronous exceptions. Cheers, Bertram P.S.: > 1. [MVars are] complex. Each MVar has 2 state transitions, each may block. It seems worth noting that the IVar state transition also blocks. > 2. [MVars do not] play well in presence of asynchronous exceptions. I can't help smirking about this claim. From tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk Fri Dec 28 18:23:54 2018 From: tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk (Tom Ellis) Date: Fri, 28 Dec 2018 18:23:54 +0000 Subject: [Haskell-cafe] OT: Re: [GSoC 2019] Call for Ideas In-Reply-To: <20181228142050.GB19905@colony6.localdomain> References: <20181228142050.GB19905@colony6.localdomain> Message-ID: <20181228182354.bblfjrplnnwjzv5z@weber> On Fri, Dec 28, 2018 at 03:20:50PM +0100, Jasper Van der Jeugt wrote: > Google Summer of Code will take place again in 2019, for the 15th year > of the program [1]! We are very proud that Haskell.Org has been able to > take part every year except for the initial year (2015) and 2016-2017, > when we had to resort to running our own program. Somewhat off-topic, but I think you mean 2005 for the initial year. https://en.wikipedia.org/wiki/Google_Summer_of_Code#2005 From m at jaspervdj.be Fri Dec 28 19:59:32 2018 From: m at jaspervdj.be (Jasper Van der Jeugt) Date: Fri, 28 Dec 2018 20:59:32 +0100 Subject: [Haskell-cafe] OT: Re: [GSoC 2019] Call for Ideas In-Reply-To: <20181228182354.bblfjrplnnwjzv5z@weber> References: <20181228142050.GB19905@colony6.localdomain> <20181228182354.bblfjrplnnwjzv5z@weber> Message-ID: Oops! You are correct -- mistake on my part. Cheers Jasper On Fri, 28 Dec 2018 at 19:24, Tom Ellis < tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > On Fri, Dec 28, 2018 at 03:20:50PM +0100, Jasper Van der Jeugt wrote: > > Google Summer of Code will take place again in 2019, for the 15th year > > of the program [1]! We are very proud that Haskell.Org has been able to > > take part every year except for the initial year (2015) and 2016-2017, > > when we had to resort to running our own program. > > Somewhat off-topic, but I think you mean 2005 for the initial year. > > https://en.wikipedia.org/wiki/Google_Summer_of_Code#2005 > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -- Jasper -------------- next part -------------- An HTML attachment was scrubbed... URL: From ietf-dane at dukhovni.org Fri Dec 28 22:25:04 2018 From: ietf-dane at dukhovni.org (Viktor Dukhovni) Date: Fri, 28 Dec 2018 17:25:04 -0500 Subject: [Haskell-cafe] MVar considered harmful In-Reply-To: <20181228174408.GI16230@24f89f8c-e6a1-4e75-85ee-bb8a3743bb9f> References: <20181228174408.GI16230@24f89f8c-e6a1-4e75-85ee-bb8a3743bb9f> Message-ID: > On Dec 28, 2018, at 12:44 PM, Bertram Felgenhauer via Haskell-Cafe wrote: > > This is awkward to fix. Basically, when abandoning the lock before it > has been released by the previous owner, we need a new thread to wait > for the 'current' IVar and notify the 'next' one, since the current > thread is being interrupted. I think that work can be delegated to the waiting thread, by making locks (really barriers) optionally chain to a parent barrier that also needs to be waited for (recursively). This is cheap, because unless threads are actually interrupted, the chain is always one deep. When a thread is interrupted, the next thread will wait for 2 barriers, ... -- Viktor. module Main (main) where import Control.Concurrent.MVar -- should be an IVar import Control.Concurrent import Control.Exception (bracket) import Data.IORef -- Really a recursive barrier newtype Lock = Lock (MVar (Maybe Lock)) type Mutex = IORef Lock type Chain = IORef (Maybe Lock) newMutex :: IO Mutex newMutex = Lock <$> newMVar Nothing >>= newIORef withMutex :: Mutex -> IO a -> IO a withMutex m = bracket swapShared signalPrivate . (\act -> (>> act) . waitChain . snd) where -- Return a new IORef containing the old barrier from the mutex, and a new -- barrier, that has been atomically swapped into the old mutex. swapShared :: IO (Lock, Chain) swapShared = Lock <$> newEmptyMVar >>= \b' -> atomicModifyIORef m (\b -> (b', b)) >>= \b -> newIORef (Just b) >>= \chain -> return (b', chain) signalPrivate :: (Lock, Chain) -> IO () signalPrivate (Lock b, chain) = readIORef chain >>= putMVar b -- The last barrier that we were waiting on (if we're interrupted) -- will be left in our chain as a "continuation" for whoever -- next gets the mutex. It may be already signalled by the time they -- see it, and that's OK. On normal return it will be 'Nothing'. waitChain :: Chain -> IO () waitChain c = readIORef c >>= go where go = mapM_ $ \(Lock a) -> readMVar a >>= \b -> writeIORef c b >> go b mkThread :: Mutex -> String -> IO ThreadId mkThread m name = do tid <- forkIO $ withMutex m $ do putStrLn $ unwords ["thread", name, "running"] threadDelay 200000 putStrLn $ unwords ["thread", name, "stopping"] yield return tid main :: IO () main = do m <- newMutex _ <- mkThread m "A" threadB <- mkThread m "B" _ <- mkThread m "C" killThread threadB threadDelay 1000000 From bertram.felgenhauer at googlemail.com Fri Dec 28 23:06:41 2018 From: bertram.felgenhauer at googlemail.com (Bertram Felgenhauer) Date: Sat, 29 Dec 2018 00:06:41 +0100 Subject: [Haskell-cafe] MVar considered harmful In-Reply-To: References: <20181228174408.GI16230@24f89f8c-e6a1-4e75-85ee-bb8a3743bb9f> Message-ID: <20181228230641.GK16230@24f89f8c-e6a1-4e75-85ee-bb8a3743bb9f> Dear Viktor, Viktor Dukhovni wrote: > > On Dec 28, 2018, at 12:44 PM, Bertram Felgenhauer via Haskell-Cafe wrote: > > This is awkward to fix. Basically, when abandoning the lock before it > > has been released by the previous owner, we need a new thread to wait > > for the 'current' IVar and notify the 'next' one, since the current > > thread is being interrupted. > > I think that work can be delegated to the waiting thread, by making > locks (really barriers) optionally chain to a parent barrier that > also needs to be waited for (recursively). This is cheap, [...] Thanks! Using the next waiting thread for cleanup work instead of spawning a fresh one is much more elegant indeed. Cheers, Bertram From quentin.liu.0415 at gmail.com Fri Dec 28 15:05:44 2018 From: quentin.liu.0415 at gmail.com (Qingbo Liu) Date: Fri, 28 Dec 2018 23:05:44 +0800 Subject: [Haskell-cafe] A few questions about unsafe IO Message-ID: Dear Cafe, I am reading an article on HaskellWiki about unsafe IO[1]. It gives the guideline about usage of unsafeDupablePerformIO: "If you need extra speed, and it's acceptable for the action to be performed multiple times, and it's acceptable if this action is canceled halfway through its execution, use unsafeDupablePerformIO.” Inside `ByteStirng` module[2], I noticed that when converting [Char] to ByteString, it uses unsafeDupablePerformIO to allocate space for the ByteString, as the following code shows (important information highlighted): packChars :: [Char] -> ByteString packChars cs = unsafePackLenChars (List.length cs) cs : unsafePackLenBytes :: Int -> [Word8] -> ByteString unsafePackLenBytes len xs0 = unsafeCreate len $ \p -> go p xs0 where go !_ [] = return () go !p (x:xs) = poke p x >> go (p `plusPtr` 1) xs unsafeCreate :: Int -> (Ptr Word8 -> IO ()) -> ByteString unsafeCreate l f = unsafeDupablePerformIO (create l f) -- | A way of creating ByteStrings outside the IO monad. The @Int@ -- argument gives the final size of the ByteString. -- | Create ByteString of size @l@ and use action @f@ to fill it's contents. create :: Int -> (Ptr Word8 -> IO ()) -> IO ByteString create l f = do fp <- mallocByteString l withForeignPtr fp $ \p -> f p return $! PS fp 0 l {-# INLINE create #-} -- | Wrapper of 'mallocForeignPtrBytes' with faster implementation for GHC -- mallocByteString :: Int -> IO (ForeignPtr a) mallocByteString = mallocPlainForeignPtrBytes {-# INLINE mallocByteString #-} The doc of `mallocPlainForeignPtrBytes`, however, explicitly says that no finalizer is added for the allocated memory. So my question is: would not the allocation code in ByteString module cause memory leaks? The doc of `unsafeDupablePerformIO` mentions that it "duplicated IO actions is only run partially, and then interrupted in the middle without an exception being raised”. Thus, it might happen that we have already allocated the memory but then the action is interrupted, without reclaiming the memory. [1] https://wiki.haskell.org/Evaluation_order_and_state_tokens [2] http://hackage.haskell.org/package/bytestring-0.10.8.2/docs/src/Data.ByteString.Internal.html#ByteString Best Regards, Qingbo Liu -------------- next part -------------- An HTML attachment was scrubbed... URL: From damien.mattei at gmail.com Sat Dec 29 09:08:32 2018 From: damien.mattei at gmail.com (Damien Mattei) Date: Sat, 29 Dec 2018 10:08:32 +0100 Subject: [Haskell-cafe] Fwd: IO monad use In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Damien Mattei Date: Sat, Dec 29, 2018 at 9:46 AM Subject: IO monad use To: Damien MATTEI again an annoying error with my code, i want to apply sort of MAP on list resut of my database IO accessed extracting info with another query, queries works both but i can not MAP or if i can i do not know how to SHOW the result, here is the code: lstNamesBD <- mapM (\(Only name) -> do let nameStr = Text.unpack name bd <- getBD conn nameStr (nameStr,bd)) names it fails to compile with this error: Prelude> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:203:33: error: • Couldn't match type ‘(,) String’ with ‘IO’ Expected type: IO (Maybe Float) Actual type: (String, Maybe Float) • In a stmt of a 'do' block: (nameStr, bd) In the expression: do let nameStr = unpack name bd <- getBD conn nameStr (nameStr, bd) In the first argument of ‘mapM’, namely ‘(\ (Only name) -> do let nameStr = ... bd <- getBD conn nameStr (nameStr, bd))’ | 203 | (nameStr,bd)) | ^^^^^^^^^^^^ Failed, no modules loaded. if i code like this show does not know how to display result: let lstNamesBD = Prelude.map (\(Only name) -> do let nameStr = Text.unpack name bd <- getBD conn nameStr res <- (nameStr,bd) res) names putStr "lstNamesBD =" putStrLn $ show lstNamesBD *Main> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:193:16: error: • No instance for (Show (IO (Maybe Float))) arising from a use of ‘show’ • In the second argument of ‘($)’, namely ‘show lstNamesBD’ In a stmt of a 'do' block: putStrLn $ show lstNamesBD In the expression: do conn <- connect defaultConnectInfo {connectHost = "moita", connectUser = "mattei", connectPassword = "sidonie2", connectDatabase = "sidonie"} (rows :: [(Text, Double)]) <- query_ conn "SELECT Nom,distance FROM AngularDistance WHERE distance > 0.000278" (names :: [Only Text]) <- query_ conn "SELECT Nom FROM AngularDistance WHERE distance > 0.000278" let resLstNames = Prelude.map fromOnly names .... | 193 | putStrLn $ show lstNamesBD | ^^^^^^^^^^^^^^^ Failed, no modules loaded. help me please -------------- next part -------------- An HTML attachment was scrubbed... URL: From william.fearon at mail.com Sat Dec 29 10:23:57 2018 From: william.fearon at mail.com (William Fearon) Date: Sat, 29 Dec 2018 11:23:57 +0100 Subject: [Haskell-cafe] MVar considered harmful In-Reply-To: References: <20181228174408.GI16230@24f89f8c-e6a1-4e75-85ee-bb8a3743bb9f> Message-ID: An HTML attachment was scrubbed... URL: From magicloud.magiclouds at gmail.com Sat Dec 29 10:23:47 2018 From: magicloud.magiclouds at gmail.com (Magicloud Magiclouds) Date: Sat, 29 Dec 2018 18:23:47 +0800 Subject: [Haskell-cafe] About understanding FunBind in haskell-src-exts. Message-ID: Hi, Recently I am playing with haskell-src-exts to help understanding Haskell syntax more. Then I got this question. As top level declarations (the type Decl), TypeSig, PatBind are quite straight forward, they mean one item in the source. But `FunBind l [Match l] `, I could not see it maps to "one item" in the source. Apparently, the list of Match can hold a few non-related functions with different names. Then why a FunBind to hold them together? -- 竹密岂妨流水过 山高哪阻野云飞 From tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk Sat Dec 29 10:30:04 2018 From: tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk (Tom Ellis) Date: Sat, 29 Dec 2018 10:30:04 +0000 Subject: [Haskell-cafe] Fwd: IO monad use In-Reply-To: References: Message-ID: <20181229103004.uuc4qhaq6wejfruy@weber> I guess you want return (nameStr, bd) Every statement in a do-block must be of type `IO a` for some `a`. `(nameStr, bd)` is a pure value of type `(String, Maybe Float)`. You turn it into a value of type `IO (String, Maybe Float)` using `return`. Tom On Sat, Dec 29, 2018 at 10:08:32AM +0100, Damien Mattei wrote: > ---------- Forwarded message --------- > From: Damien Mattei > Date: Sat, Dec 29, 2018 at 9:46 AM > Subject: IO monad use > To: Damien MATTEI > > > again an annoying error with my code, i want to apply sort of MAP on list > resut of my database IO accessed extracting info with another query, > queries works both but i can not MAP or if i can i do not know how to SHOW > the result, here is the code: > > lstNamesBD <- mapM (\(Only name) -> > do > let nameStr = Text.unpack name > bd <- getBD conn nameStr > (nameStr,bd)) > names > > it fails to compile with this error: > > Prelude> :load UpdateSidonie > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > UpdateSidonie.hs:203:33: error: > • Couldn't match type ‘(,) String’ with ‘IO’ > Expected type: IO (Maybe Float) > Actual type: (String, Maybe Float) > • In a stmt of a 'do' block: (nameStr, bd) > In the expression: > do let nameStr = unpack name > bd <- getBD conn nameStr > (nameStr, bd) > In the first argument of ‘mapM’, namely > ‘(\ (Only name) > -> do let nameStr = ... > bd <- getBD conn nameStr > (nameStr, bd))’ > | > 203 | (nameStr,bd)) > | ^^^^^^^^^^^^ > Failed, no modules loaded. > > > if i code like this show does not know how to display result: > > let lstNamesBD = Prelude.map (\(Only name) -> > do > let nameStr = Text.unpack name > bd <- getBD conn nameStr > res <- (nameStr,bd) > res) > names > > putStr "lstNamesBD =" > putStrLn $ show lstNamesBD > > *Main> :load UpdateSidonie > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > UpdateSidonie.hs:193:16: error: > • No instance for (Show (IO (Maybe Float))) > arising from a use of ‘show’ > • In the second argument of ‘($)’, namely ‘show lstNamesBD’ > In a stmt of a 'do' block: putStrLn $ show lstNamesBD > In the expression: > do conn <- connect > defaultConnectInfo > {connectHost = "moita", connectUser = "mattei", > connectPassword = "sidonie2", connectDatabase = > "sidonie"} > (rows :: [(Text, Double)]) <- query_ > conn > "SELECT Nom,distance FROM > AngularDistance WHERE distance > 0.000278" > (names :: [Only Text]) <- query_ > conn > "SELECT Nom FROM AngularDistance > WHERE distance > 0.000278" > let resLstNames = Prelude.map fromOnly names > .... > | > 193 | putStrLn $ show lstNamesBD > | ^^^^^^^^^^^^^^^ > Failed, no modules loaded. > > help me please > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. From william.fearon at mail.com Sat Dec 29 10:32:54 2018 From: william.fearon at mail.com (William Fearon) Date: Sat, 29 Dec 2018 11:32:54 +0100 Subject: [Haskell-cafe] Jan 2018- Membership of the Group Message-ID: An HTML attachment was scrubbed... URL: From damien.mattei at gmail.com Sat Dec 29 10:42:05 2018 From: damien.mattei at gmail.com (Damien Mattei) Date: Sat, 29 Dec 2018 11:42:05 +0100 Subject: [Haskell-cafe] Fwd: IO monad use In-Reply-To: <20181229103004.uuc4qhaq6wejfruy@weber> References: <20181229103004.uuc4qhaq6wejfruy@weber> Message-ID: thank you tom, in fact reading doc as i saw i never used return read in monad doc i already put it in my code this gives this that compiles: let lstNamesBD = Prelude.map (\(Only name) -> do let strName = Text.unpack name getBD conn strName >>= (\bd -> return (strName,bd))) names but sticked now for displaying it because it is now an IO tuple of 2 and i can not display it with some functions like this , it fails to compile: -- putStr "lstNamesBD =" -- putStrLn $ show lstNamesBD forM_ lstNamesBD $ \t2 -> do n <- fst t2 b <- snd t2 putStrLn $ (show n) ++ " " ++ maybe "NULL" show b or with that tested first: forM_ lstNamesBD $ \(name,bd) -> putStrLn $ (show name) ++ " " ++ maybe "NULL" show bd Prelude> :load UpdateSidonie [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) UpdateSidonie.hs:207:22: error: • Couldn't match expected type ‘(IO a1, b0)’ with actual type ‘IO (String, Maybe Float)’ • In the first argument of ‘fst’, namely ‘t2’ In a stmt of a 'do' block: n <- fst t2 In the expression: do n <- fst t2 b <- snd t2 putStrLn $ (show n) ++ " " ++ maybe "NULL" show b | 207 | n <- fst t2 | ^^ UpdateSidonie.hs:208:22: error: • Couldn't match expected type ‘(a0, IO (Maybe a2))’ with actual type ‘IO (String, Maybe Float)’ • In the first argument of ‘snd’, namely ‘t2’ In a stmt of a 'do' block: b <- snd t2 In the expression: do n <- fst t2 b <- snd t2 putStrLn $ (show n) ++ " " ++ maybe "NULL" show b | 208 | b <- snd t2 | ^^ UpdateSidonie.hs:211:25: error: • Couldn't match expected type ‘IO (String, Maybe Float)’ with actual type ‘(a3, Maybe a4)’ • In the pattern: (name, bd) In the second argument of ‘($)’, namely ‘\ (name, bd) -> putStrLn $ (show name) ++ " " ++ maybe "NULL" show bd’ In a stmt of a 'do' block: forM_ lstNamesBD $ \ (name, bd) -> putStrLn $ (show name) ++ " " ++ maybe "NULL" show bd | 211 | forM_ lstNamesBD $ \(name,bd) -> | ^^^^^^^^^ Failed, no modules loaded. Prelude> On Sat, Dec 29, 2018 at 11:30 AM Tom Ellis < tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > I guess you want > > return (nameStr, bd) > > Every statement in a do-block must be of type `IO a` for some `a`. > `(nameStr, bd)` is a pure value of type `(String, Maybe Float)`. You turn > it into a value of type `IO (String, Maybe Float)` using `return`. > > Tom > > On Sat, Dec 29, 2018 at 10:08:32AM +0100, Damien Mattei wrote: > > ---------- Forwarded message --------- > > From: Damien Mattei > > Date: Sat, Dec 29, 2018 at 9:46 AM > > Subject: IO monad use > > To: Damien MATTEI > > > > > > again an annoying error with my code, i want to apply sort of MAP on > list > > resut of my database IO accessed extracting info with another query, > > queries works both but i can not MAP or if i can i do not know how to > SHOW > > the result, here is the code: > > > > lstNamesBD <- mapM (\(Only name) -> > > do > > let nameStr = Text.unpack name > > bd <- getBD conn nameStr > > (nameStr,bd)) > > names > > > > it fails to compile with this error: > > > > Prelude> :load UpdateSidonie > > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > > > UpdateSidonie.hs:203:33: error: > > • Couldn't match type ‘(,) String’ with ‘IO’ > > Expected type: IO (Maybe Float) > > Actual type: (String, Maybe Float) > > • In a stmt of a 'do' block: (nameStr, bd) > > In the expression: > > do let nameStr = unpack name > > bd <- getBD conn nameStr > > (nameStr, bd) > > In the first argument of ‘mapM’, namely > > ‘(\ (Only name) > > -> do let nameStr = ... > > bd <- getBD conn nameStr > > (nameStr, bd))’ > > | > > 203 | (nameStr,bd)) > > | ^^^^^^^^^^^^ > > Failed, no modules loaded. > > > > > > if i code like this show does not know how to display result: > > > > let lstNamesBD = Prelude.map (\(Only name) -> > > do > > let nameStr = Text.unpack name > > bd <- getBD conn nameStr > > res <- (nameStr,bd) > > res) > > names > > > > putStr "lstNamesBD =" > > putStrLn $ show lstNamesBD > > > > *Main> :load UpdateSidonie > > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > > > UpdateSidonie.hs:193:16: error: > > • No instance for (Show (IO (Maybe Float))) > > arising from a use of ‘show’ > > • In the second argument of ‘($)’, namely ‘show lstNamesBD’ > > In a stmt of a 'do' block: putStrLn $ show lstNamesBD > > In the expression: > > do conn <- connect > > defaultConnectInfo > > {connectHost = "moita", connectUser = "mattei", > > connectPassword = "sidonie2", connectDatabase = > > "sidonie"} > > (rows :: [(Text, Double)]) <- query_ > > conn > > "SELECT Nom,distance FROM > > AngularDistance WHERE distance > 0.000278" > > (names :: [Only Text]) <- query_ > > conn > > "SELECT Nom FROM AngularDistance > > WHERE distance > 0.000278" > > let resLstNames = Prelude.map fromOnly names > > .... > > | > > 193 | putStrLn $ show lstNamesBD > > | ^^^^^^^^^^^^^^^ > > Failed, no modules loaded. > > > > help me please > > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sergueyz at gmail.com Sat Dec 29 10:43:11 2018 From: sergueyz at gmail.com (Serguey Zefirov) Date: Sat, 29 Dec 2018 13:43:11 +0300 Subject: [Haskell-cafe] MVar considered harmful In-Reply-To: References: Message-ID: MVar and IVar things are from dataflow programming, I believe, from Id90 programming language (read about it, it's fascinating). They were ued there with greate success (linear scaling on CM-5, no less; they had to invent throttling to tame huge parallelism available). MVar were used for synchronization and IVars to provide a kind of call-by-need in a lenient language. Mind that Id90 was not as sofisticated as Haskell today and these things were used as a coordination tool between huge number of small threads of execution, with no I/O and all threads must work to completion. Thus, they are, as usually happens, not general purpose yet very useful. I consider them "baby-STM". But what it takes to consider them harmful is beyond me. чт, 20 дек. 2018 г. в 00:02, Станислав Черничкин : > Recently I had an interesting discussion on MVars with cats-effect library > designers. Cats-effect brings MVar synchronization primitive along with > other IO stuff to the Scala programming language. I tried to persuade them > to include some Control.Concurrent.MVar’s functions to the library but has > failed completely. Moreover, now I think that MVar is a poor choice for > basic synchronization primitive. Your may find discussion here > https://github.com/typelevel/cats-effect/issues/451 and event try to > advocate, tl;dr. Anyway, what is so wrong with MVar? > > 1. It’s complex. Each MVar has 2 state transitions, each may block. > > 2. It does not play well in presence of asynchronous exceptions. > More specifically, `take` and `put` operations should be balanced (each > `take` must be followed by `put`) this force programmer to mask > asynchronous exceptions during the MVar acquisition and since `take` > function may block, this will delay task cancelation. Well, you may argue > what the `takeMVar` function is actually interruptible, but I’m going to > show an easier approach which renders interpretability magic unnecessary. > > What could be the sensible alternative? Guy from the cats-effect suggested > me IVar + atomic reference (IORef). This pattern separates concern of > blocking (synchronization) from the atomic mutation. So everything can be > represented as atomic reference with IVar inside. Just look at this > beautiful mutex implementation > https://github.com/ovotech/fs2-kafka/blob/master/src/main/scala/fs2/kafka/internal/Synchronized.scala > (By ”beautiful” I mean approach itself of course, but not the Scala’s > syntax. Scala is one of most ugliest girls after C++ I was forced to date > with by my employer for money. Thankfully he didn’t force me to do the same > things with her grandma Java). > > For people who don’t read Scala, the approach is fairly simple. Each > thread which want to touch mutex, will create IVar, atomically swap it in > the IORef masked (note, that IORef’s operations non-blocking), unmask and > wait for previous become available IVar *unmasked*. Then it will either > perform it’s operations or fail due to the interruption or exception and > trigger newly installed IVar anyway. It just works. Without any > «interruptible» magic. > > So, which benefits can we get? > > 1. Simpler implementation of basic primitives. Obliviously IORef is > fairly simple. IVar is also mind be simpler than MVar, and possibly faster > (just “possibly”, I don’t know how it’s implemented, but I guess lesser > state transitions implies less logic). > > 2. Simplified deadlock analysis. Really, we have only IVar with > only one state transition and only one potentially blocking operation. > > 3. Magicless support of interruptions. We don’t need to separate > mask/uninterruptibleMask anymore, because all updates are non-blocking, and > all waits are unmasked. > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk Sat Dec 29 10:51:11 2018 From: tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk (Tom Ellis) Date: Sat, 29 Dec 2018 10:51:11 +0000 Subject: [Haskell-cafe] Fwd: IO monad use In-Reply-To: References: <20181229103004.uuc4qhaq6wejfruy@weber> Message-ID: <20181229105111.b4wqp7oqk6bycg5w@weber> Why are you using map? You were right the first time with mapM: lstNamesBD <- mapM (\(Only name) -> do let nameStr = Text.unpack name bd <- getBD conn nameStr return (nameStr,bd)) names On Sat, Dec 29, 2018 at 11:42:05AM +0100, Damien Mattei wrote: > thank you tom, > in fact reading doc as i saw i never used return read in monad doc i > already put it in my code this gives this that compiles: > let lstNamesBD = Prelude.map (\(Only name) -> > do > let strName = Text.unpack name > getBD conn strName >>= (\bd -> > > return (strName,bd))) > names > > but sticked now for displaying it because it is now an IO tuple of 2 and i > can not display it with some functions like this , it fails to compile: > > -- putStr "lstNamesBD =" > -- putStrLn $ show lstNamesBD > > forM_ lstNamesBD $ \t2 -> > do > n <- fst t2 > b <- snd t2 > putStrLn $ (show n) ++ " " ++ maybe "NULL" show b > > or with that tested first: > > forM_ lstNamesBD $ \(name,bd) -> > putStrLn $ (show name) ++ " " ++ maybe "NULL" show bd > Prelude> :load UpdateSidonie > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > UpdateSidonie.hs:207:22: error: > • Couldn't match expected type ‘(IO a1, b0)’ > with actual type ‘IO (String, Maybe Float)’ > • In the first argument of ‘fst’, namely ‘t2’ > In a stmt of a 'do' block: n <- fst t2 > In the expression: > do n <- fst t2 > b <- snd t2 > putStrLn $ (show n) ++ " " ++ maybe "NULL" show b > | > 207 | n <- fst t2 > | ^^ > > UpdateSidonie.hs:208:22: error: > • Couldn't match expected type ‘(a0, IO (Maybe a2))’ > with actual type ‘IO (String, Maybe Float)’ > • In the first argument of ‘snd’, namely ‘t2’ > In a stmt of a 'do' block: b <- snd t2 > In the expression: > do n <- fst t2 > b <- snd t2 > putStrLn $ (show n) ++ " " ++ maybe "NULL" show b > | > 208 | b <- snd t2 > | ^^ > > UpdateSidonie.hs:211:25: error: > • Couldn't match expected type ‘IO (String, Maybe Float)’ > with actual type ‘(a3, Maybe a4)’ > • In the pattern: (name, bd) > In the second argument of ‘($)’, namely > ‘\ (name, bd) > -> putStrLn $ (show name) ++ " " ++ maybe "NULL" show bd’ > In a stmt of a 'do' block: > forM_ lstNamesBD > $ \ (name, bd) > -> putStrLn $ (show name) ++ " " ++ maybe "NULL" show bd > | > 211 | forM_ lstNamesBD $ \(name,bd) -> > | ^^^^^^^^^ > Failed, no modules loaded. > Prelude> > > > On Sat, Dec 29, 2018 at 11:30 AM Tom Ellis < > tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > > > I guess you want > > > > return (nameStr, bd) > > > > Every statement in a do-block must be of type `IO a` for some `a`. > > `(nameStr, bd)` is a pure value of type `(String, Maybe Float)`. You turn > > it into a value of type `IO (String, Maybe Float)` using `return`. > > > > Tom > > > > On Sat, Dec 29, 2018 at 10:08:32AM +0100, Damien Mattei wrote: > > > ---------- Forwarded message --------- > > > From: Damien Mattei > > > Date: Sat, Dec 29, 2018 at 9:46 AM > > > Subject: IO monad use > > > To: Damien MATTEI > > > > > > > > > again an annoying error with my code, i want to apply sort of MAP on > > list > > > resut of my database IO accessed extracting info with another query, > > > queries works both but i can not MAP or if i can i do not know how to > > SHOW > > > the result, here is the code: > > > > > > lstNamesBD <- mapM (\(Only name) -> > > > do > > > let nameStr = Text.unpack name > > > bd <- getBD conn nameStr > > > (nameStr,bd)) > > > names > > > > > > it fails to compile with this error: > > > > > > Prelude> :load UpdateSidonie > > > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > > > > > UpdateSidonie.hs:203:33: error: > > > • Couldn't match type ‘(,) String’ with ‘IO’ > > > Expected type: IO (Maybe Float) > > > Actual type: (String, Maybe Float) > > > • In a stmt of a 'do' block: (nameStr, bd) > > > In the expression: > > > do let nameStr = unpack name > > > bd <- getBD conn nameStr > > > (nameStr, bd) > > > In the first argument of ‘mapM’, namely > > > ‘(\ (Only name) > > > -> do let nameStr = ... > > > bd <- getBD conn nameStr > > > (nameStr, bd))’ > > > | > > > 203 | (nameStr,bd)) > > > | ^^^^^^^^^^^^ > > > Failed, no modules loaded. > > > > > > > > > if i code like this show does not know how to display result: > > > > > > let lstNamesBD = Prelude.map (\(Only name) -> > > > do > > > let nameStr = Text.unpack name > > > bd <- getBD conn nameStr > > > res <- (nameStr,bd) > > > res) > > > names > > > > > > putStr "lstNamesBD =" > > > putStrLn $ show lstNamesBD > > > > > > *Main> :load UpdateSidonie > > > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > > > > > UpdateSidonie.hs:193:16: error: > > > • No instance for (Show (IO (Maybe Float))) > > > arising from a use of ‘show’ > > > • In the second argument of ‘($)’, namely ‘show lstNamesBD’ > > > In a stmt of a 'do' block: putStrLn $ show lstNamesBD > > > In the expression: > > > do conn <- connect > > > defaultConnectInfo > > > {connectHost = "moita", connectUser = "mattei", > > > connectPassword = "sidonie2", connectDatabase = > > > "sidonie"} > > > (rows :: [(Text, Double)]) <- query_ > > > conn > > > "SELECT Nom,distance FROM > > > AngularDistance WHERE distance > 0.000278" > > > (names :: [Only Text]) <- query_ > > > conn > > > "SELECT Nom FROM AngularDistance > > > WHERE distance > 0.000278" > > > let resLstNames = Prelude.map fromOnly names > > > .... > > > | > > > 193 | putStrLn $ show lstNamesBD > > > | ^^^^^^^^^^^^^^^ > > > Failed, no modules loaded. > > > > > > help me please > > > > > _______________________________________________ > > > Haskell-Cafe mailing list > > > To (un)subscribe, modify options or view archives go to: > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > > Only members subscribed via the mailman list are allowed to post. > > > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. From magicloud.magiclouds at gmail.com Sat Dec 29 11:39:44 2018 From: magicloud.magiclouds at gmail.com (Magicloud Magiclouds) Date: Sat, 29 Dec 2018 19:39:44 +0800 Subject: [Haskell-cafe] About understanding FunBind in haskell-src-exts. In-Reply-To: References: Message-ID: Hi, I can see the case of one FunBind contains multiple Matches, like this one. But I cannot see why the "name" (isJust) is in Match, instead of FunBind. Are there cases other than yours that a few functions having different names should be grouped together? PS: FunBind and Match definitions: FunBind l [Match l] Match l (Name l) [Pat l] (Rhs l) (Maybe (Binds l)) On Sat, Dec 29, 2018 at 6:56 PM Alan & Kim Zimmerman wrote: > > This is for the case when you have a function like > > isJust Nothing = False > isJust (Maybe _) = True > > This is a single FunBind for isJust, but has two Matches > > Alan > > On Sat, 29 Dec 2018 at 12:25, Magicloud Magiclouds wrote: >> >> Hi, >> >> Recently I am playing with haskell-src-exts to help understanding >> Haskell syntax more. Then I got this question. >> >> As top level declarations (the type Decl), TypeSig, PatBind are quite >> straight forward, they mean one item in the source. But `FunBind l >> [Match l] >> `, I could not see it maps to "one item" in the source. >> >> Apparently, the list of Match can hold a few non-related functions >> with different names. Then why a FunBind to hold them together? >> >> -- >> 竹密岂妨流水过 >> 山高哪阻野云飞 >> _______________________________________________ >> Haskell-Cafe mailing list >> To (un)subscribe, modify options or view archives go to: >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> Only members subscribed via the mailman list are allowed to post. -- 竹密岂妨流水过 山高哪阻野云飞 And for G+, please use magiclouds#gmail.com. From allbery.b at gmail.com Sat Dec 29 13:28:00 2018 From: allbery.b at gmail.com (Brandon Allbery) Date: Sat, 29 Dec 2018 08:28:00 -0500 Subject: [Haskell-cafe] MVar considered harmful In-Reply-To: References: Message-ID: Having no sense of either history or implementation. On Sat, Dec 29, 2018 at 5:43 AM Serguey Zefirov wrote: > MVar and IVar things are from dataflow programming, I believe, from Id90 > programming language (read about it, it's fascinating). They were ued there > with greate success (linear scaling on CM-5, no less; they had to invent > throttling to tame huge parallelism available). MVar were used for > synchronization and IVars to provide a kind of call-by-need in a lenient > language. Mind that Id90 was not as sofisticated as Haskell today and these > things were used as a coordination tool between huge number of small > threads of execution, with no I/O and all threads must work to completion. > > Thus, they are, as usually happens, not general purpose yet very useful. I > consider them "baby-STM". > > But what it takes to consider them harmful is beyond me. > > чт, 20 дек. 2018 г. в 00:02, Станислав Черничкин : > >> Recently I had an interesting discussion on MVars with cats-effect >> library designers. Cats-effect brings MVar synchronization primitive along >> with other IO stuff to the Scala programming language. I tried to persuade >> them to include some Control.Concurrent.MVar’s functions to the library >> but has failed completely. Moreover, now I think that MVar is a poor choice >> for basic synchronization primitive. Your may find discussion here >> https://github.com/typelevel/cats-effect/issues/451 and event try to >> advocate, tl;dr. Anyway, what is so wrong with MVar? >> >> 1. It’s complex. Each MVar has 2 state transitions, each may >> block. >> >> 2. It does not play well in presence of asynchronous exceptions. >> More specifically, `take` and `put` operations should be balanced (each >> `take` must be followed by `put`) this force programmer to mask >> asynchronous exceptions during the MVar acquisition and since `take` >> function may block, this will delay task cancelation. Well, you may argue >> what the `takeMVar` function is actually interruptible, but I’m going to >> show an easier approach which renders interpretability magic unnecessary. >> >> What could be the sensible alternative? Guy from the cats-effect >> suggested me IVar + atomic reference (IORef). This pattern separates >> concern of blocking (synchronization) from the atomic mutation. So >> everything can be represented as atomic reference with IVar inside. Just >> look at this beautiful mutex implementation >> https://github.com/ovotech/fs2-kafka/blob/master/src/main/scala/fs2/kafka/internal/Synchronized.scala >> (By ”beautiful” I mean approach itself of course, but not the Scala’s >> syntax. Scala is one of most ugliest girls after C++ I was forced to date >> with by my employer for money. Thankfully he didn’t force me to do the same >> things with her grandma Java). >> >> For people who don’t read Scala, the approach is fairly simple. Each >> thread which want to touch mutex, will create IVar, atomically swap it in >> the IORef masked (note, that IORef’s operations non-blocking), unmask and >> wait for previous become available IVar *unmasked*. Then it will either >> perform it’s operations or fail due to the interruption or exception and >> trigger newly installed IVar anyway. It just works. Without any >> «interruptible» magic. >> >> So, which benefits can we get? >> >> 1. Simpler implementation of basic primitives. Obliviously IORef >> is fairly simple. IVar is also mind be simpler than MVar, and possibly >> faster (just “possibly”, I don’t know how it’s implemented, but I guess >> lesser state transitions implies less logic). >> >> 2. Simplified deadlock analysis. Really, we have only IVar with >> only one state transition and only one potentially blocking operation. >> >> 3. Magicless support of interruptions. We don’t need to separate >> mask/uninterruptibleMask anymore, because all updates are non-blocking, and >> all waits are unmasked. >> _______________________________________________ >> Haskell-Cafe mailing list >> To (un)subscribe, modify options or view archives go to: >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> Only members subscribed via the mailman list are allowed to post. > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -- brandon s allbery kf8nh allbery.b at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From damien.mattei at gmail.com Sat Dec 29 13:38:53 2018 From: damien.mattei at gmail.com (Damien Mattei) Date: Sat, 29 Dec 2018 14:38:53 +0100 Subject: [Haskell-cafe] Fwd: IO monad use In-Reply-To: <20181229105111.b4wqp7oqk6bycg5w@weber> References: <20181229103004.uuc4qhaq6wejfruy@weber> <20181229105111.b4wqp7oqk6bycg5w@weber> Message-ID: yes it works, i had not set the return in the mapM version, that's my problem with i too often throw dices, do not know why its mapM or map that works, i put a return in a deseperate moment.... :-) still learning monads, find this that explain the concept: http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html#translations and this but just at the beginning i am: https://wiki.haskell.org/All_About_Monads thanks again for your help Damien On Sat, Dec 29, 2018 at 11:51 AM Tom Ellis < tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > Why are you using map? You were right the first time with mapM: > > lstNamesBD <- mapM (\(Only name) -> > do > let nameStr = Text.unpack name > bd <- getBD conn nameStr > return (nameStr,bd)) > names > > On Sat, Dec 29, 2018 at 11:42:05AM +0100, Damien Mattei wrote: > > thank you tom, > > in fact reading doc as i saw i never used return read in monad doc i > > already put it in my code this gives this that compiles: > > let lstNamesBD = Prelude.map (\(Only name) -> > > do > > let strName = Text.unpack name > > getBD conn strName >>= (\bd -> > > > > return (strName,bd))) > > names > > > > but sticked now for displaying it because it is now an IO tuple of 2 and > i > > can not display it with some functions like this , it fails to compile: > > > > -- putStr "lstNamesBD =" > > -- putStrLn $ show lstNamesBD > > > > forM_ lstNamesBD $ \t2 -> > > do > > n <- fst t2 > > b <- snd t2 > > putStrLn $ (show n) ++ " " ++ maybe "NULL" show b > > > > or with that tested first: > > > > forM_ lstNamesBD $ \(name,bd) -> > > putStrLn $ (show name) ++ " " ++ maybe "NULL" show bd > > Prelude> :load UpdateSidonie > > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > > > UpdateSidonie.hs:207:22: error: > > • Couldn't match expected type ‘(IO a1, b0)’ > > with actual type ‘IO (String, Maybe Float)’ > > • In the first argument of ‘fst’, namely ‘t2’ > > In a stmt of a 'do' block: n <- fst t2 > > In the expression: > > do n <- fst t2 > > b <- snd t2 > > putStrLn $ (show n) ++ " " ++ maybe "NULL" show b > > | > > 207 | n <- fst t2 > > | ^^ > > > > UpdateSidonie.hs:208:22: error: > > • Couldn't match expected type ‘(a0, IO (Maybe a2))’ > > with actual type ‘IO (String, Maybe Float)’ > > • In the first argument of ‘snd’, namely ‘t2’ > > In a stmt of a 'do' block: b <- snd t2 > > In the expression: > > do n <- fst t2 > > b <- snd t2 > > putStrLn $ (show n) ++ " " ++ maybe "NULL" show b > > | > > 208 | b <- snd t2 > > | ^^ > > > > UpdateSidonie.hs:211:25: error: > > • Couldn't match expected type ‘IO (String, Maybe Float)’ > > with actual type ‘(a3, Maybe a4)’ > > • In the pattern: (name, bd) > > In the second argument of ‘($)’, namely > > ‘\ (name, bd) > > -> putStrLn $ (show name) ++ " " ++ maybe "NULL" show bd’ > > In a stmt of a 'do' block: > > forM_ lstNamesBD > > $ \ (name, bd) > > -> putStrLn $ (show name) ++ " " ++ maybe "NULL" show bd > > | > > 211 | forM_ lstNamesBD $ \(name,bd) -> > > | ^^^^^^^^^ > > Failed, no modules loaded. > > Prelude> > > > > > > On Sat, Dec 29, 2018 at 11:30 AM Tom Ellis < > > tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > > > > > I guess you want > > > > > > return (nameStr, bd) > > > > > > Every statement in a do-block must be of type `IO a` for some `a`. > > > `(nameStr, bd)` is a pure value of type `(String, Maybe Float)`. You > turn > > > it into a value of type `IO (String, Maybe Float)` using `return`. > > > > > > Tom > > > > > > On Sat, Dec 29, 2018 at 10:08:32AM +0100, Damien Mattei wrote: > > > > ---------- Forwarded message --------- > > > > From: Damien Mattei > > > > Date: Sat, Dec 29, 2018 at 9:46 AM > > > > Subject: IO monad use > > > > To: Damien MATTEI > > > > > > > > > > > > again an annoying error with my code, i want to apply sort of MAP on > > > list > > > > resut of my database IO accessed extracting info with another query, > > > > queries works both but i can not MAP or if i can i do not know how to > > > SHOW > > > > the result, here is the code: > > > > > > > > lstNamesBD <- mapM (\(Only name) -> > > > > do > > > > let nameStr = Text.unpack name > > > > bd <- getBD conn nameStr > > > > (nameStr,bd)) > > > > names > > > > > > > > it fails to compile with this error: > > > > > > > > Prelude> :load UpdateSidonie > > > > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > > > > > > > UpdateSidonie.hs:203:33: error: > > > > • Couldn't match type ‘(,) String’ with ‘IO’ > > > > Expected type: IO (Maybe Float) > > > > Actual type: (String, Maybe Float) > > > > • In a stmt of a 'do' block: (nameStr, bd) > > > > In the expression: > > > > do let nameStr = unpack name > > > > bd <- getBD conn nameStr > > > > (nameStr, bd) > > > > In the first argument of ‘mapM’, namely > > > > ‘(\ (Only name) > > > > -> do let nameStr = ... > > > > bd <- getBD conn nameStr > > > > (nameStr, bd))’ > > > > | > > > > 203 | (nameStr,bd)) > > > > | ^^^^^^^^^^^^ > > > > Failed, no modules loaded. > > > > > > > > > > > > if i code like this show does not know how to display result: > > > > > > > > let lstNamesBD = Prelude.map (\(Only name) -> > > > > do > > > > let nameStr = Text.unpack > name > > > > bd <- getBD conn nameStr > > > > res <- (nameStr,bd) > > > > res) > > > > names > > > > > > > > putStr "lstNamesBD =" > > > > putStrLn $ show lstNamesBD > > > > > > > > *Main> :load UpdateSidonie > > > > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > > > > > > > UpdateSidonie.hs:193:16: error: > > > > • No instance for (Show (IO (Maybe Float))) > > > > arising from a use of ‘show’ > > > > • In the second argument of ‘($)’, namely ‘show lstNamesBD’ > > > > In a stmt of a 'do' block: putStrLn $ show lstNamesBD > > > > In the expression: > > > > do conn <- connect > > > > defaultConnectInfo > > > > {connectHost = "moita", connectUser = > "mattei", > > > > connectPassword = "sidonie2", > connectDatabase = > > > > "sidonie"} > > > > (rows :: [(Text, Double)]) <- query_ > > > > conn > > > > "SELECT Nom,distance FROM > > > > AngularDistance WHERE distance > 0.000278" > > > > (names :: [Only Text]) <- query_ > > > > conn > > > > "SELECT Nom FROM > AngularDistance > > > > WHERE distance > 0.000278" > > > > let resLstNames = Prelude.map fromOnly names > > > > .... > > > > | > > > > 193 | putStrLn $ show lstNamesBD > > > > | ^^^^^^^^^^^^^^^ > > > > Failed, no modules loaded. > > > > > > > > help me please > > > > > > > _______________________________________________ > > > > Haskell-Cafe mailing list > > > > To (un)subscribe, modify options or view archives go to: > > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > > > Only members subscribed via the mailman list are allowed to post. > > > > > > _______________________________________________ > > > Haskell-Cafe mailing list > > > To (un)subscribe, modify options or view archives go to: > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > > Only members subscribed via the mailman list are allowed to post. > > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk Sat Dec 29 14:02:34 2018 From: tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk (Tom Ellis) Date: Sat, 29 Dec 2018 14:02:34 +0000 Subject: [Haskell-cafe] Fwd: IO monad use In-Reply-To: References: <20181229103004.uuc4qhaq6wejfruy@weber> <20181229105111.b4wqp7oqk6bycg5w@weber> Message-ID: <20181229140234.ogvjwrzxb6p5b2fi@weber> I suggest you look carefully at the types of the things you are combining. Once you understand how the types fit together you will understand which functions you should use. On Sat, Dec 29, 2018 at 02:38:53PM +0100, Damien Mattei wrote: > yes it works, i had not set the return > in the mapM version, that's my problem with i too often throw dices, do not > know why its mapM or map that works, i put a return in a deseperate > moment.... :-) > still learning monads, find this that explain the concept: > > http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html#translations > > and this but just at the beginning i am: > https://wiki.haskell.org/All_About_Monads > > thanks again for your help > Damien > > On Sat, Dec 29, 2018 at 11:51 AM Tom Ellis < > tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > > > Why are you using map? You were right the first time with mapM: > > > > lstNamesBD <- mapM (\(Only name) -> > > do > > let nameStr = Text.unpack name > > bd <- getBD conn nameStr > > return (nameStr,bd)) > > names > > > > On Sat, Dec 29, 2018 at 11:42:05AM +0100, Damien Mattei wrote: > > > thank you tom, > > > in fact reading doc as i saw i never used return read in monad doc i > > > already put it in my code this gives this that compiles: > > > let lstNamesBD = Prelude.map (\(Only name) -> > > > do > > > let strName = Text.unpack name > > > getBD conn strName >>= (\bd -> > > > > > > return (strName,bd))) > > > names > > > > > > but sticked now for displaying it because it is now an IO tuple of 2 and > > i > > > can not display it with some functions like this , it fails to compile: > > > > > > -- putStr "lstNamesBD =" > > > -- putStrLn $ show lstNamesBD > > > > > > forM_ lstNamesBD $ \t2 -> > > > do > > > n <- fst t2 > > > b <- snd t2 > > > putStrLn $ (show n) ++ " " ++ maybe "NULL" show b > > > > > > or with that tested first: > > > > > > forM_ lstNamesBD $ \(name,bd) -> > > > putStrLn $ (show name) ++ " " ++ maybe "NULL" show bd > > > Prelude> :load UpdateSidonie > > > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > > > > > UpdateSidonie.hs:207:22: error: > > > • Couldn't match expected type ‘(IO a1, b0)’ > > > with actual type ‘IO (String, Maybe Float)’ > > > • In the first argument of ‘fst’, namely ‘t2’ > > > In a stmt of a 'do' block: n <- fst t2 > > > In the expression: > > > do n <- fst t2 > > > b <- snd t2 > > > putStrLn $ (show n) ++ " " ++ maybe "NULL" show b > > > | > > > 207 | n <- fst t2 > > > | ^^ > > > > > > UpdateSidonie.hs:208:22: error: > > > • Couldn't match expected type ‘(a0, IO (Maybe a2))’ > > > with actual type ‘IO (String, Maybe Float)’ > > > • In the first argument of ‘snd’, namely ‘t2’ > > > In a stmt of a 'do' block: b <- snd t2 > > > In the expression: > > > do n <- fst t2 > > > b <- snd t2 > > > putStrLn $ (show n) ++ " " ++ maybe "NULL" show b > > > | > > > 208 | b <- snd t2 > > > | ^^ > > > > > > UpdateSidonie.hs:211:25: error: > > > • Couldn't match expected type ‘IO (String, Maybe Float)’ > > > with actual type ‘(a3, Maybe a4)’ > > > • In the pattern: (name, bd) > > > In the second argument of ‘($)’, namely > > > ‘\ (name, bd) > > > -> putStrLn $ (show name) ++ " " ++ maybe "NULL" show bd’ > > > In a stmt of a 'do' block: > > > forM_ lstNamesBD > > > $ \ (name, bd) > > > -> putStrLn $ (show name) ++ " " ++ maybe "NULL" show bd > > > | > > > 211 | forM_ lstNamesBD $ \(name,bd) -> > > > | ^^^^^^^^^ > > > Failed, no modules loaded. > > > Prelude> > > > > > > > > > On Sat, Dec 29, 2018 at 11:30 AM Tom Ellis < > > > tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote: > > > > > > > I guess you want > > > > > > > > return (nameStr, bd) > > > > > > > > Every statement in a do-block must be of type `IO a` for some `a`. > > > > `(nameStr, bd)` is a pure value of type `(String, Maybe Float)`. You > > turn > > > > it into a value of type `IO (String, Maybe Float)` using `return`. > > > > > > > > Tom > > > > > > > > On Sat, Dec 29, 2018 at 10:08:32AM +0100, Damien Mattei wrote: > > > > > ---------- Forwarded message --------- > > > > > From: Damien Mattei > > > > > Date: Sat, Dec 29, 2018 at 9:46 AM > > > > > Subject: IO monad use > > > > > To: Damien MATTEI > > > > > > > > > > > > > > > again an annoying error with my code, i want to apply sort of MAP on > > > > list > > > > > resut of my database IO accessed extracting info with another query, > > > > > queries works both but i can not MAP or if i can i do not know how to > > > > SHOW > > > > > the result, here is the code: > > > > > > > > > > lstNamesBD <- mapM (\(Only name) -> > > > > > do > > > > > let nameStr = Text.unpack name > > > > > bd <- getBD conn nameStr > > > > > (nameStr,bd)) > > > > > names > > > > > > > > > > it fails to compile with this error: > > > > > > > > > > Prelude> :load UpdateSidonie > > > > > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > > > > > > > > > UpdateSidonie.hs:203:33: error: > > > > > • Couldn't match type ‘(,) String’ with ‘IO’ > > > > > Expected type: IO (Maybe Float) > > > > > Actual type: (String, Maybe Float) > > > > > • In a stmt of a 'do' block: (nameStr, bd) > > > > > In the expression: > > > > > do let nameStr = unpack name > > > > > bd <- getBD conn nameStr > > > > > (nameStr, bd) > > > > > In the first argument of ‘mapM’, namely > > > > > ‘(\ (Only name) > > > > > -> do let nameStr = ... > > > > > bd <- getBD conn nameStr > > > > > (nameStr, bd))’ > > > > > | > > > > > 203 | (nameStr,bd)) > > > > > | ^^^^^^^^^^^^ > > > > > Failed, no modules loaded. > > > > > > > > > > > > > > > if i code like this show does not know how to display result: > > > > > > > > > > let lstNamesBD = Prelude.map (\(Only name) -> > > > > > do > > > > > let nameStr = Text.unpack > > name > > > > > bd <- getBD conn nameStr > > > > > res <- (nameStr,bd) > > > > > res) > > > > > names > > > > > > > > > > putStr "lstNamesBD =" > > > > > putStrLn $ show lstNamesBD > > > > > > > > > > *Main> :load UpdateSidonie > > > > > [1 of 1] Compiling Main ( UpdateSidonie.hs, interpreted ) > > > > > > > > > > UpdateSidonie.hs:193:16: error: > > > > > • No instance for (Show (IO (Maybe Float))) > > > > > arising from a use of ‘show’ > > > > > • In the second argument of ‘($)’, namely ‘show lstNamesBD’ > > > > > In a stmt of a 'do' block: putStrLn $ show lstNamesBD > > > > > In the expression: > > > > > do conn <- connect > > > > > defaultConnectInfo > > > > > {connectHost = "moita", connectUser = > > "mattei", > > > > > connectPassword = "sidonie2", > > connectDatabase = > > > > > "sidonie"} > > > > > (rows :: [(Text, Double)]) <- query_ > > > > > conn > > > > > "SELECT Nom,distance FROM > > > > > AngularDistance WHERE distance > 0.000278" > > > > > (names :: [Only Text]) <- query_ > > > > > conn > > > > > "SELECT Nom FROM > > AngularDistance > > > > > WHERE distance > 0.000278" > > > > > let resLstNames = Prelude.map fromOnly names > > > > > .... > > > > > | > > > > > 193 | putStrLn $ show lstNamesBD > > > > > | ^^^^^^^^^^^^^^^ > > > > > Failed, no modules loaded. > > > > > > > > > > help me please > > > > > > > > > _______________________________________________ > > > > > Haskell-Cafe mailing list > > > > > To (un)subscribe, modify options or view archives go to: > > > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > > > > Only members subscribed via the mailman list are allowed to post. > > > > > > > > _______________________________________________ > > > > Haskell-Cafe mailing list > > > > To (un)subscribe, modify options or view archives go to: > > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > > > Only members subscribed via the mailman list are allowed to post. > > > > > _______________________________________________ > > > Haskell-Cafe mailing list > > > To (un)subscribe, modify options or view archives go to: > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > > Only members subscribed via the mailman list are allowed to post. > > > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. From zemyla at gmail.com Sun Dec 30 01:02:44 2018 From: zemyla at gmail.com (Zemyla) Date: Sat, 29 Dec 2018 19:02:44 -0600 Subject: [Haskell-cafe] A few questions about unsafe IO In-Reply-To: References: Message-ID: No finalizer is added for the allocated memory because the address given is just that of a pinned ByteArray, which is garbage collected. If the operation is interrupted, then the memory will be reclaimed during the next GC cycle. On Fri, Dec 28, 2018 at 9:26 PM Qingbo Liu wrote: > > Dear Cafe, > > I am reading an article on HaskellWiki about unsafe IO[1]. It gives the guideline about usage of unsafeDupablePerformIO: "If you need extra speed, and it's acceptable for the action to be performed multiple times, and it's acceptable if this action is canceled halfway through its execution, use unsafeDupablePerformIO.” Inside `ByteStirng` module[2], I noticed that when converting [Char] to ByteString, it uses unsafeDupablePerformIO to allocate space for the ByteString, as the following code shows (important information highlighted): > > packChars :: [Char] -> ByteString > packChars cs = unsafePackLenChars (List.length cs) cs : > > unsafePackLenBytes :: Int -> [Word8] -> ByteString > unsafePackLenBytes len xs0 = > unsafeCreate len $ \p -> go p xs0 > where > go !_ [] = return () > go !p (x:xs) = poke p x >> go (p `plusPtr` 1) xs > > unsafeCreate :: Int -> (Ptr Word8 -> IO ()) -> ByteString > unsafeCreate l f = unsafeDupablePerformIO (create l f) > > -- | A way of creating ByteStrings outside the IO monad. The @Int@ > -- argument gives the final size of the ByteString. > > -- | Create ByteString of size @l@ and use action @f@ to fill it's contents. > create :: Int -> (Ptr Word8 -> IO ()) -> IO ByteString > create l f = do > fp <- mallocByteString l > withForeignPtr fp $ \p -> f p > return $! PS fp 0 l > {-# INLINE create #-} > > -- | Wrapper of 'mallocForeignPtrBytes' with faster implementation for GHC > -- > mallocByteString :: Int -> IO (ForeignPtr a) > mallocByteString = mallocPlainForeignPtrBytes > {-# INLINE mallocByteString #-} > > > The doc of `mallocPlainForeignPtrBytes`, however, explicitly says that no finalizer is added for the allocated memory. So my question is: would not the allocation code in ByteString module cause memory leaks? > > The doc of `unsafeDupablePerformIO` mentions that it "duplicated IO actions is only run partially, and then interrupted in the middle without an exception being raised”. Thus, it might happen that we have already allocated the memory but then the action is interrupted, without reclaiming the memory. > > > [1] https://wiki.haskell.org/Evaluation_order_and_state_tokens > [2] http://hackage.haskell.org/package/bytestring-0.10.8.2/docs/src/Data.ByteString.Internal.html#ByteString > > Best Regards, > Qingbo Liu > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. From jo at durchholz.org Sun Dec 30 07:22:23 2018 From: jo at durchholz.org (Joachim Durchholz) Date: Sun, 30 Dec 2018 08:22:23 +0100 Subject: [Haskell-cafe] MVar considered harmful In-Reply-To: References: Message-ID: Am 29.12.18 um 11:43 schrieb Serguey Zefirov: > MVar and IVar things are from dataflow programming, I believe, from Id90 > programming language (read about it, it's fascinating). They were ued > there with greate success (linear scaling on CM-5, no less; they had to > invent throttling to tame huge parallelism available). So they were forced to go sublinear - that makes the claim pretty shady IMHO. Claims of linearly scaling parallelism are usually wrong. First, there's always coordination overhead. Even if tasks distribute perfectly, it's there - not much, but if you didn't notice it, either you didn't scale up far enough to see the effect, or your measurements are off. Second, there's always a bottleneck somewhere. E.g. for GPU parallelism, there's a pretty hard limit on the amount of data you can transfer over the bus. You *can* work around that by setting up a hierarchical compute node organization, which was all the rage for a few years, but it never took off; I guess the constant factors have been too high. So, forgive me if I am sceptical about that Id90 claim of linear scaling. Regards, Jo From abimelech at gmail.com Sun Dec 30 07:44:43 2018 From: abimelech at gmail.com (Leif Warner) Date: Sat, 29 Dec 2018 23:44:43 -0800 Subject: [Haskell-cafe] Taking over the udev package Message-ID: I'm offering to take over the "udev" package on hackage. I have some code which depends on it, as well as a PR to allow it to build on GHC 8.4, among other things: https://github.com/pxqr/udev/pull/5 It looks like the author, Samvel Truzyan, has been inactive on GitHub and Twitter for the past couple of years. Ilya Portnov might also be a good candidate to maintain this package - Ilya has the wacom-daemon package on hackage which depends on udev, and also has previously submitted a PR which has been merged to the udev package. -Leif Warner -------------- next part -------------- An HTML attachment was scrubbed... URL: From william.fearon at mail.com Mon Dec 31 16:09:09 2018 From: william.fearon at mail.com (William Fearon) Date: Mon, 31 Dec 2018 17:09:09 +0100 Subject: [Haskell-cafe] Jan 2019- Membership of the Group Message-ID: An HTML attachment was scrubbed... URL: From quentin.liu.0415 at gmail.com Mon Dec 31 04:06:20 2018 From: quentin.liu.0415 at gmail.com (Qingbo Liu) Date: Mon, 31 Dec 2018 12:06:20 +0800 Subject: [Haskell-cafe] A few questions about unsafe IO In-Reply-To: References: Message-ID: Oh I see. Thank you! I tried to search for some articles particularly on finalizers in Haskell but most I found were just documentations. So according to the documentation in Foreign.ForeignPtr, finalizers associated with a foreign pointer will be invoked when there are no more references to the pointer, with the finalizers typically being the routine of a foreign language. If the finalizer of a foreign pointer does not do anything, e.g. it ignores the argument, will the memory allocated for the foreign pointer be garbage collected? In other words, are the finalizers typically used for cleaning up resources such as file handles (but not memory)? Best Regards, Qingbo Liu On Dec 30, 2018, 09:03 +0800, Zemyla , wrote: > No finalizer is added for the allocated memory because the address > given is just that of a pinned ByteArray, which is garbage collected. > If the operation is interrupted, then the memory will be reclaimed > during the next GC cycle. > > On Fri, Dec 28, 2018 at 9:26 PM Qingbo Liu wrote: > > > > Dear Cafe, > > > > I am reading an article on HaskellWiki about unsafe IO[1]. It gives the guideline about usage of unsafeDupablePerformIO: "If you need extra speed, and it's acceptable for the action to be performed multiple times, and it's acceptable if this action is canceled halfway through its execution, use unsafeDupablePerformIO.” Inside `ByteStirng` module[2], I noticed that when converting [Char] to ByteString, it uses unsafeDupablePerformIO to allocate space for the ByteString, as the following code shows (important information highlighted): > > > > packChars :: [Char] -> ByteString > > packChars cs = unsafePackLenChars (List.length cs) cs : > > > > unsafePackLenBytes :: Int -> [Word8] -> ByteString > > unsafePackLenBytes len xs0 = > > unsafeCreate len $ \p -> go p xs0 > > where > > go !_ [] = return () > > go !p (x:xs) = poke p x >> go (p `plusPtr` 1) xs > > > > unsafeCreate :: Int -> (Ptr Word8 -> IO ()) -> ByteString > > unsafeCreate l f = unsafeDupablePerformIO (create l f) > > > > -- | A way of creating ByteStrings outside the IO monad. The @Int@ > > -- argument gives the final size of the ByteString. > > > > -- | Create ByteString of size @l@ and use action @f@ to fill it's contents. > > create :: Int -> (Ptr Word8 -> IO ()) -> IO ByteString > > create l f = do > > fp <- mallocByteString l > > withForeignPtr fp $ \p -> f p > > return $! PS fp 0 l > > {-# INLINE create #-} > > > > -- | Wrapper of 'mallocForeignPtrBytes' with faster implementation for GHC > > -- > > mallocByteString :: Int -> IO (ForeignPtr a) > > mallocByteString = mallocPlainForeignPtrBytes > > {-# INLINE mallocByteString #-} > > > > > > The doc of `mallocPlainForeignPtrBytes`, however, explicitly says that no finalizer is added for the allocated memory. So my question is: would not the allocation code in ByteString module cause memory leaks? > > > > The doc of `unsafeDupablePerformIO` mentions that it "duplicated IO actions is only run partially, and then interrupted in the middle without an exception being raised”. Thus, it might happen that we have already allocated the memory but then the action is interrupted, without reclaiming the memory. > > > > > > [1] https://wiki.haskell.org/Evaluation_order_and_state_tokens > > [2] http://hackage.haskell.org/package/bytestring-0.10.8.2/docs/src/Data.ByteString.Internal.html#ByteString > > > > Best Regards, > > Qingbo Liu > > _______________________________________________ > > Haskell-Cafe mailing list > > To (un)subscribe, modify options or view archives go to: > > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > > Only members subscribed via the mailman list are allowed to post. > _______________________________________________ > Haskell-Cafe mailing list > To (un)subscribe, modify options or view archives go to: > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe > Only members subscribed via the mailman list are allowed to post. -------------- next part -------------- An HTML attachment was scrubbed... URL: