From 47dragonfyre at gmail.com Mon Feb 1 04:49:39 2021 From: 47dragonfyre at gmail.com (A. Mc.) Date: Sun, 31 Jan 2021 20:49:39 -0800 Subject: [Haskell-beginners] Using Functions with Fold Message-ID: Hello, I feel like I need to go back to basics, so I've made a toy problem that takes a list of Ints, say [10, 20, 30, 40, 50, 60] and, in theory, iterates through the list in successive pairs i.e. [10, 20], [20, 30], [30, 40], [40, 50], [50, 60] and looks for a specific pair set, say 30, 40, and accumulates the number of times that pair appears in the list (for example purpose, there are no repeats, but assuming there were....). What I've done is the following: ---take starting at position 2, in increments of 2 with overlap allowed takeAtTwo :: [Int] -> Int -> [Int] takeAtTwo list position = take (2 + position) list ---expects range of 0 to length list - 2 grabTwo :: [Int] -> Int -> [Int] grabTwo list position = drop position (takeAtTwo list position) -- and this does NOT work, half-pseudocode --- pass in a pair of Int, say [30, 40] and sum up the number of appearances numPair list = foldr (\pair acc -> if grabTwo list iterator == pair then acc + 1 else acc) 0 However, I am unsure how to get this to work properly with fold. Suggestions? Thanks in advance and thank you for your time. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Mon Feb 1 05:07:32 2021 From: fa-ml at ariis.it (Francesco Ariis) Date: Mon, 1 Feb 2021 06:07:32 +0100 Subject: [Haskell-beginners] Using Functions with Fold In-Reply-To: References: Message-ID: <20210201050732.GA21439@extensa> Il 31 gennaio 2021 alle 20:49 A. Mc. ha scritto: > I feel like I need to go back to basics, so I've made a toy problem that > takes a list of Ints, say [10, 20, 30, 40, 50, 60] and, in theory, iterates > through the list in successive pairs i.e. [10, 20], [20, 30], [30, 40], > [40, 50], [50, 60] and looks for a specific pair set, say 30, 40, and > accumulates the number of times that pair appears in the list (for example > purpose, there are no repeats, but assuming there were....). What I've > done is the following: > > ---take starting at position 2, in increments of 2 with overlap allowed > takeAtTwo :: [Int] -> Int -> [Int] > takeAtTwo list position = take (2 + position) list > > ---expects range of 0 to length list - 2 > grabTwo :: [Int] -> Int -> [Int] > grabTwo list position = drop position (takeAtTwo list position) > > -- and this does NOT work, half-pseudocode > --- pass in a pair of Int, say [30, 40] and sum up the number of appearances > numPair list = foldr (\pair acc -> if grabTwo list iterator == pair then > acc + 1 else acc) 0 > > However, I am unsure how to get this to work properly with fold. > Suggestions? Thanks in advance and thank you for your time. You might have better luck with first generating the pairs and then passing them to another function. λ> prova as = zip as (tail as) λ> prova [10,20..60] [(10,20),(20,30),(30,40),(40,50),(50,60)] Counting now is a simple matter of λ> length . filter (==(30,40)) $ it 1 -- or use a fold if you prefer From leduin.cuenca at yachaytech.edu.ec Wed Feb 3 21:01:51 2021 From: leduin.cuenca at yachaytech.edu.ec (=?UTF-8?Q?Leduin_Jos=C3=A9_Cuenca_Macas?=) Date: Wed, 3 Feb 2021 16:01:51 -0500 Subject: [Haskell-beginners] Data Types and Functions Visualization Message-ID: Hey, there! Do you know about any tool to generate a graph that connects data types through functions of my program? I tried stack dot but only I obtained the relationship of dependencies. Greetings! *Leduin José Cuenca Macas* *Student | Estudiante* Tel. (+593) 991 618 273 -------------- next part -------------- An HTML attachment was scrubbed... URL: From conrad.dev at mail.com Fri Feb 5 06:27:06 2021 From: conrad.dev at mail.com (Corrado Corrado) Date: Fri, 5 Feb 2021 07:27:06 +0100 Subject: [Haskell-beginners] type variables - error: 'No instance for' Message-ID: An HTML attachment was scrubbed... URL: From dj112358 at outlook.com Fri Feb 5 09:41:54 2021 From: dj112358 at outlook.com (David James) Date: Fri, 5 Feb 2021 09:41:54 +0000 Subject: [Haskell-beginners] type variables - error: 'No instance for' In-Reply-To: References: Message-ID: Hello, Have a look at this: > mytriple (1 :: Integer) 'a' 'b' :418:28: error: • Couldn't match expected type ‘Integer’ with actual type ‘Char’ • In the third argument of ‘mytriple’, namely ‘'b'’ In the expression: mytriple (1 :: Integer) 'a' 'b' In an equation for ‘it’: it = mytriple (1 :: Integer) 'a' 'b' This is probably what you expected. In this case, you’ve explicitly stated that 1 is a value of type Integer. But look at the type here: > :t 3 3 :: Num p => p This might be a bit confusing. Haskell supports many different types of number (Int, Integer, Double, Complex, etc). Although they are different types, they are all instances of the same class (Num). When you type 1 (or some other numeric literal) into GHCi, it doesn’t (yet) know which of these types you want, but does know it has to be a type that’s an instance of Num, which is what the type signature gives. Hence you can do: > 3 `mod` 2 1 (which treats the 3 as some integral type), or > 3 / 2 1.5 (which treats the 3 as a fractional – i.e. non-integral- type) Now it knows more about the type of 3 needed, it will ensure it is of a more specific type. If typeclasses are new to you, you might want to read something like this. Now look at: > :t (+) (+) :: Num a => a -> a -> a This says (+) can add two values of the same type, as long as that type is an instance of class Num. Hence: > 3 + 'a' :407:1: error: • No instance for (Num Char) arising from a use of ‘+’ • In the expression: 3 + 'a' In an equation for ‘it’: it = 3 + 'a' This now makes sense: ‘a’ is of type Char, and there is no instance declaration instance Num Char (since Char’s are not numbers). Your example is much the same. In order for mytriple 1 'a' 'b' to typecheck: ‘b’ must be a Char, and 1 must also be a Char, but 1 has to be a type that’s an instance of Num, so would require an instance Num Char to exist. Hope that all makes sense, David. From: Corrado Corrado Sent: 05 February 2021 06:27 To: beginners at haskell.org Subject: [Haskell-beginners] type variables - error: 'No instance for' Hello, I defined a simple function as below: mytriple :: a -> b -> a -> (a,b,a); mytriple x y z = (x,y,z); Then I checked 'mytriple' type variables signatures, so I declared a mytriple values in a 'wrong way': ____ should be to the same type of the 1st argument / λ:t2 = mytriple 1 'a' 'b' error: 'No instance for (Num Char) arising from the literal '1' 'In the first argument of mytriple', namely '1' In the expression: mytriple 1 'a' 'b' In an equation for 't2': t2 = mytriple 1 'a' 'b' Ok, this is exactly what I aspected, but I do not understand the error. What means the sentence : 'No instance for (Num Char) arising from the literal '1'.' How is evaluated a function, in order to check that the params are type variables signatures? Why the error message refers to the 1st arguments? Thanks Conrad -------------- next part -------------- An HTML attachment was scrubbed... URL: From borgauf at gmail.com Fri Feb 5 18:22:52 2021 From: borgauf at gmail.com (Lawrence Bottorff) Date: Fri, 5 Feb 2021 12:22:52 -0600 Subject: [Haskell-beginners] Mixed division Message-ID: I can divide a float by an integer > 2.4 / 3 0.7999999999999999 but why can I not do this? < 2.4 / (length [1,2,3]) :288:1-22: error: * No instance for (Fractional Int) arising from a use of `/' * In the expression: 2.4 / (length [1, 2, 3]) LB -------------- next part -------------- An HTML attachment was scrubbed... URL: From utprimum at gmail.com Fri Feb 5 18:28:51 2021 From: utprimum at gmail.com (Ut Primum) Date: Fri, 5 Feb 2021 19:28:51 +0100 Subject: [Haskell-beginners] Mixed division In-Reply-To: References: Message-ID: Hi, when you write 3 Haskell sees it as a "num" while the type of the length [1,2,3] is "int". So 3 and length [1,2,3] have not the same type. Il ven 5 feb 2021, 19:23 Lawrence Bottorff ha scritto: > I can divide a float by an integer > > > 2.4 / 3 > 0.7999999999999999 > > but why can I not do this? > > < 2.4 / (length [1,2,3]) > :288:1-22: error: > * No instance for (Fractional Int) arising from a use of `/' > * In the expression: 2.4 / (length [1, 2, 3]) > > LB > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From borgauf at gmail.com Fri Feb 5 18:36:03 2021 From: borgauf at gmail.com (Lawrence Bottorff) Date: Fri, 5 Feb 2021 12:36:03 -0600 Subject: [Haskell-beginners] Mixed division In-Reply-To: References: Message-ID: This works myAvg :: [Float] -> Float myAvg [] = 0.0 myAvg xs = (foldr (+) 0.0 xs) / (fromIntegral (length xs) :: Float) but is there a simpler way to "cast" the value of (length xs)? On Fri, Feb 5, 2021 at 12:29 PM Ut Primum wrote: > Hi, > when you write 3 Haskell sees it as a "num" while the type of the length > [1,2,3] is "int". So 3 and length [1,2,3] have not the same type. > > Il ven 5 feb 2021, 19:23 Lawrence Bottorff ha scritto: > >> I can divide a float by an integer >> >> > 2.4 / 3 >> 0.7999999999999999 >> >> but why can I not do this? >> >> < 2.4 / (length [1,2,3]) >> :288:1-22: error: >> * No instance for (Fractional Int) arising from a use of `/' >> * In the expression: 2.4 / (length [1, 2, 3]) >> >> LB >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From 47dragonfyre at gmail.com Sat Feb 6 00:42:52 2021 From: 47dragonfyre at gmail.com (A. Mc.) Date: Fri, 5 Feb 2021 16:42:52 -0800 Subject: [Haskell-beginners] Cabal Build Message-ID: Hello, I've been trying to do a cabal build. I'm using Windows 10. But, after going through cabal init, change diretories, run, etc it keeps telling me I don't have permission. My project also has 2 libraries that I wrote for main, and although I tried editing the .cabal file, I'm not sure I have it right. Thanks in advance and thank you for your time. -------------- next part -------------- An HTML attachment was scrubbed... URL: From borgauf at gmail.com Sat Feb 6 04:18:31 2021 From: borgauf at gmail.com (Lawrence Bottorff) Date: Fri, 5 Feb 2021 22:18:31 -0600 Subject: [Haskell-beginners] Function with mod cases? Message-ID: I'm looking through *An Introduction to Functional Programming Systems Using Haskell *by Davie and one of the exercises is *Define a function* f *such that* f(x) = x + 3 (mod 5) *Make a version that elaborates cases, as well as a straightforward way.* I'm not really sure what's being asked, so this is what I've come up with myMods xs = map (\x -> (x + 3) `mod` 5) xs > myMods [1..20] [4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3] but when he says *make a version that elaborates cases *I'm not sure what more there is to do. What am I missing? LB -------------- next part -------------- An HTML attachment was scrubbed... URL: From borgauf at gmail.com Fri Feb 12 23:01:44 2021 From: borgauf at gmail.com (Galaxy Being) Date: Fri, 12 Feb 2021 17:01:44 -0600 Subject: [Haskell-beginners] Recursive calls inside lazy data constructors? Message-ID: I'm looking at this from Stackoverflow and wondering what is meant in the accepted answer when he says *In Haskell you can safely do recursive calls inside lazy data constructors, and there will be no risk of stack overflow or divergence. Placing the recursive call inside a constructor eliminates the need for an accumulator, and the order of elements in the list will also correspond to the order in which they are computed*: collatz :: Integer -> [Integer] collatz n | n <= 1 = [] collatz n = n : collatz next where next = if even n then div n 2 else n * 3 + 1 What is meant by lazy data constructor in this context? LB -------------- next part -------------- An HTML attachment was scrubbed... URL: From utprimum at gmail.com Sat Feb 13 07:49:48 2021 From: utprimum at gmail.com (Ut Primum) Date: Sat, 13 Feb 2021 08:49:48 +0100 Subject: [Haskell-beginners] Recursive calls inside lazy data constructors? In-Reply-To: References: Message-ID: Hi, the sequence defined in your example has been conjectured by Collatz to be finite for all initial n. But by now this property hasn't been proved. So, for what we know, there could be an integer such that the sequence starting form it is infinite (no such n has been found yet, but there could be one). Anyway, even if such n existed, you chose it, and wrote x=collatz n there would not be a stack overflow. This is because computations will be done "lazily", so just when really needed. So if you asked for the first, say, 10 elements of the list x, they would be computed without problems, even if the base case is never reached. Of course if you asked to print collatz n for an n that makes the sequence infinite, the printing would never end. But you could make many operations with the possibly infinite list, if they required just a finite (not necessarily a priori bounded) number of elements. So in Haskell you can define lists or other data structures that are infinite. Of course you must define the structure in such a way that to compute the "next" element of the list there is no need to look at "future" elements, but just at "past" ones. I hope this answers your question, Cheers, Ut Il sab 13 feb 2021, 00:03 Galaxy Being ha scritto: > I'm looking at this > > from Stackoverflow and wondering what is meant in the accepted answer when > he says > > *In Haskell you can safely do recursive calls inside lazy data > constructors, and there will be no risk of stack overflow or divergence. > Placing the recursive call inside a constructor eliminates the need for an > accumulator, and the order of elements in the list will also correspond to > the order in which they are computed*: > > collatz :: Integer -> [Integer] > collatz n | n <= 1 = [] > collatz n = n : collatz next where > next = if even n then div n 2 else n * 3 + 1 > > What is meant by lazy data constructor in this context? > > LB > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From borgauf at gmail.com Sat Feb 13 20:34:02 2021 From: borgauf at gmail.com (Galaxy Being) Date: Sat, 13 Feb 2021 14:34:02 -0600 Subject: [Haskell-beginners] Recursive calls inside lazy data constructors? In-Reply-To: References: Message-ID: I was wondering about why he calls this a "data constructor". Is this a general use of the idea of "date constructor?" On Sat, Feb 13, 2021 at 1:50 AM Ut Primum wrote: > Hi, > the sequence defined in your example has been conjectured by Collatz to be > finite for all initial n. But by now this property hasn't been proved. > So, for what we know, there could be an integer such that the sequence > starting form it is infinite (no such n has been found yet, but there could > be one). > Anyway, even if such n existed, you chose it, and wrote > > x=collatz n > > there would not be a stack overflow. This is because computations will be > done "lazily", so just when really needed. So if you asked for the first, > say, 10 elements of the list x, they would be computed without problems, > even if the base case is never reached. Of course if you asked to print > collatz n for an n that makes the sequence infinite, the printing would > never end. But you could make many operations with the possibly infinite > list, if they required just a finite (not necessarily a priori bounded) > number of elements. > > So in Haskell you can define lists or other data structures that are > infinite. Of course you must define the structure in such a way that to > compute the "next" element of the list there is no need to look at "future" > elements, but just at "past" ones. > > I hope this answers your question, > Cheers, > Ut > > Il sab 13 feb 2021, 00:03 Galaxy Being ha scritto: > >> I'm looking at this >> >> from Stackoverflow and wondering what is meant in the accepted answer when >> he says >> >> *In Haskell you can safely do recursive calls inside lazy data >> constructors, and there will be no risk of stack overflow or divergence. >> Placing the recursive call inside a constructor eliminates the need for an >> accumulator, and the order of elements in the list will also correspond to >> the order in which they are computed*: >> >> collatz :: Integer -> [Integer] >> collatz n | n <= 1 = [] >> collatz n = n : collatz next where >> next = if even n then div n 2 else n * 3 + 1 >> >> What is meant by lazy data constructor in this context? >> >> LB >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From 47dragonfyre at gmail.com Wed Feb 17 04:49:38 2021 From: 47dragonfyre at gmail.com (A. Mc.) Date: Tue, 16 Feb 2021 20:49:38 -0800 Subject: [Haskell-beginners] Add Global Package Message-ID: Hello, I'm attempting to install and update the .yaml file so I don't have to run the command $ stack ghci --package random every single time I want to load a module that imports System.Random. Or maybe I need to use chocolatey? I don't know, but being able to use System.Random like every other package would be greatly appreciated. Right now, I'm not sure what command I need to use to do that. Thanks in advance and thank you for your time. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Wed Feb 17 07:07:33 2021 From: fa-ml at ariis.it (Francesco Ariis) Date: Wed, 17 Feb 2021 08:07:33 +0100 Subject: [Haskell-beginners] Add Global Package In-Reply-To: References: Message-ID: <20210217070732.GA23243@extensa> Il 16 febbraio 2021 alle 20:49 A. Mc. ha scritto: > I'm attempting to install and update the .yaml file so I don't have to run > the command $ stack ghci --package random every single time I want to load > a module that imports System.Random. Or maybe I need to use chocolatey? No idea with stack, but with cabal is: cabal install --lib random From jeffbrown.the at gmail.com Wed Feb 17 13:07:19 2021 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Wed, 17 Feb 2021 08:07:19 -0500 Subject: [Haskell-beginners] Add Global Package In-Reply-To: <20210217070732.GA23243@extensa> References: <20210217070732.GA23243@extensa> Message-ID: If you use Stack then you can add a .cabal file to your project that indicates what it depends on. Here's an example I use: https://github.com/JeffreyBenjaminBrown/montevideo/blob/master/mtv-util/mtv-util.cabal (It uses the `random` package too; if you search for "random" you'll find the dependencies.) Stack has global config options too: https://docs.haskellstack.org/en/stable/yaml_configuration/ which seems likely to offer the same capability; I don't know how to do it that way as I always work within a project with a cabal file. On Wed, Feb 17, 2021 at 2:08 AM Francesco Ariis wrote: > Il 16 febbraio 2021 alle 20:49 A. Mc. ha scritto: > > I'm attempting to install and update the .yaml file so I don't have to > run > > the command $ stack ghci --package random every single time I want to > load > > a module that imports System.Random. Or maybe I need to use chocolatey? > > No idea with stack, but with cabal is: > > cabal install --lib random > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Jeff Brown | Jeffrey Benjamin Brown LinkedIn | Github | Twitter | Facebook | very old Website -------------- next part -------------- An HTML attachment was scrubbed... URL: From borgauf at gmail.com Wed Feb 17 17:13:19 2021 From: borgauf at gmail.com (Galaxy Being) Date: Wed, 17 Feb 2021 11:13:19 -0600 Subject: [Haskell-beginners] import question Message-ID: I'm trying to use Decimal but (I'm guessing) I don't know how to import it. import Data.Decimal dList :: [Decimal] dList = [1.1,1.2..2.0] : :70:11-17: error: : Not in scope: type constructor or class `Decimal' Obviously I was asleep the day the teacher told us how to do this. . . . LB -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Wed Feb 17 18:57:00 2021 From: fa-ml at ariis.it (Francesco Ariis) Date: Wed, 17 Feb 2021 19:57:00 +0100 Subject: [Haskell-beginners] import question In-Reply-To: References: Message-ID: <20210217185700.GA30720@extensa> Il 17 febbraio 2021 alle 11:13 Galaxy Being ha scritto: > I'm trying to use Decimal but (I'm guessing) I don't know how to import it. > > import Data.Decimal > > dList :: [Decimal] > dList = [1.1,1.2..2.0] > > : :70:11-17: error: > : Not in scope: type constructor or class `Decimal' Works here. You need to add `Decimal` the dependencies of your project or install it globally first —F From amindfv at mailbox.org Wed Feb 17 19:58:35 2021 From: amindfv at mailbox.org (amindfv at mailbox.org) Date: Wed, 17 Feb 2021 12:58:35 -0700 Subject: [Haskell-beginners] import question In-Reply-To: References: Message-ID: <20210217195835.GA18315@painter.painter> Is it possible you mean to use Double or Float instead of Decimal? Tom On Wed, Feb 17, 2021 at 11:13:19AM -0600, Galaxy Being wrote: > I'm trying to use Decimal but (I'm guessing) I don't know how to import it. > > import Data.Decimal > > dList :: [Decimal] > dList = [1.1,1.2..2.0] > > : :70:11-17: error: > : Not in scope: type constructor or class `Decimal' > > Obviously I was asleep the day the teacher told us how to do this. . . . > > LB > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From borgauf at gmail.com Wed Feb 17 20:17:32 2021 From: borgauf at gmail.com (Galaxy Being) Date: Wed, 17 Feb 2021 14:17:32 -0600 Subject: [Haskell-beginners] import question In-Reply-To: <20210217185700.GA30720@extensa> References: <20210217185700.GA30720@extensa> Message-ID: How would I install it globally? I'm not using projects, I'm just at the ghci REPL. On Wed, Feb 17, 2021 at 12:57 PM Francesco Ariis wrote: > Il 17 febbraio 2021 alle 11:13 Galaxy Being ha scritto: > > I'm trying to use Decimal but (I'm guessing) I don't know how to import > it. > > > > import Data.Decimal > > > > dList :: [Decimal] > > dList = [1.1,1.2..2.0] > > > > : :70:11-17: error: > > : Not in scope: type constructor or class `Decimal' > > Works here. You need to add `Decimal` the dependencies of your project > or install it globally first > —F > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Wed Feb 17 20:42:31 2021 From: fa-ml at ariis.it (Francesco Ariis) Date: Wed, 17 Feb 2021 21:42:31 +0100 Subject: [Haskell-beginners] import question In-Reply-To: References: <20210217185700.GA30720@extensa> Message-ID: <20210217204230.GA19781@extensa> Il 17 febbraio 2021 alle 14:17 Galaxy Being ha scritto: > How would I install it globally? I'm not using projects, I'm just at the > ghci REPL. Most likely cabal install --lib Decimal Check what Tom has said too —F From borgauf at gmail.com Thu Feb 18 01:26:37 2021 From: borgauf at gmail.com (Galaxy Being) Date: Wed, 17 Feb 2021 19:26:37 -0600 Subject: [Haskell-beginners] import question In-Reply-To: <20210217204230.GA19781@extensa> References: <20210217185700.GA30720@extensa> <20210217204230.GA19781@extensa> Message-ID: I'm trying to create a list of real numbers with a two-decimal interval, a la > [1.0,1.01,1.02,...1.99,2.00] however, I get the float approximation problem [1.0,1.01,1.02,1.03,1.04,1.05,1.06,1.07,1.08,1.09,1.1,1.11,1.12,1.1300000000000001,1.1400000000000001,... So I attempted to compensate with import Data.Decimal map (roundTo 2) [1.00,1.01..2.0] I don't have to do it this way if there is another rounding function to correct the float overrun issue. On Wed, Feb 17, 2021 at 2:43 PM Francesco Ariis wrote: > Il 17 febbraio 2021 alle 14:17 Galaxy Being ha scritto: > > How would I install it globally? I'm not using projects, I'm just at the > > ghci REPL. > > Most likely > > cabal install --lib Decimal > > Check what Tom has said too —F > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at redivi.com Thu Feb 18 02:36:45 2021 From: bob at redivi.com (Bob Ippolito) Date: Wed, 17 Feb 2021 18:36:45 -0800 Subject: [Haskell-beginners] import question In-Reply-To: References: <20210217185700.GA30720@extensa> <20210217204230.GA19781@extensa> Message-ID: You don't need to do any rounding if the list is already Decimal. If you wanted to format a Double with some specific decimal representation you could look at Numeric.showFFloatAlt or similar. import Data.Decimal dList :: [Decimal] dList = [1.00,1.01..2.00] main = print dList On Wed, Feb 17, 2021 at 5:27 PM Galaxy Being wrote: > I'm trying to create a list of real numbers with a two-decimal interval, a > la > > > [1.0,1.01,1.02,...1.99,2.00] > > however, I get the float approximation problem > > > [1.0,1.01,1.02,1.03,1.04,1.05,1.06,1.07,1.08,1.09,1.1,1.11,1.12,1.1300000000000001,1.1400000000000001,... > > So I attempted to compensate with > > import Data.Decimal > map (roundTo 2) [1.00,1.01..2.0] > > I don't have to do it this way if there is another rounding function to > correct the float overrun issue. > > > > On Wed, Feb 17, 2021 at 2:43 PM Francesco Ariis wrote: > >> Il 17 febbraio 2021 alle 14:17 Galaxy Being ha scritto: >> > How would I install it globally? I'm not using projects, I'm just at the >> > ghci REPL. >> >> Most likely >> >> cabal install --lib Decimal >> >> Check what Tom has said too —F >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From borgauf at gmail.com Thu Feb 18 03:42:02 2021 From: borgauf at gmail.com (Galaxy Being) Date: Wed, 17 Feb 2021 21:42:02 -0600 Subject: [Haskell-beginners] import question In-Reply-To: References: <20210217185700.GA30720@extensa> <20210217204230.GA19781@extensa> Message-ID: As I've said, working at the ghci REPL, import Data.Decimal dList :: [Decimal] dList = [1.00,1.01..2.00] main = print dList errors out : :76:11-17: error: : Not in scope: type constructor or class `Decimal' On Wed, Feb 17, 2021 at 8:37 PM Bob Ippolito wrote: > You don't need to do any rounding if the list is already Decimal. > > If you wanted to format a Double with some specific decimal representation > you could look at Numeric.showFFloatAlt or similar. > > import Data.Decimal > > dList :: [Decimal] > dList = [1.00,1.01..2.00] > > main = print dList > > > > On Wed, Feb 17, 2021 at 5:27 PM Galaxy Being wrote: > >> I'm trying to create a list of real numbers with a two-decimal interval, >> a la >> >> > [1.0,1.01,1.02,...1.99,2.00] >> >> however, I get the float approximation problem >> >> >> [1.0,1.01,1.02,1.03,1.04,1.05,1.06,1.07,1.08,1.09,1.1,1.11,1.12,1.1300000000000001,1.1400000000000001,... >> >> So I attempted to compensate with >> >> import Data.Decimal >> map (roundTo 2) [1.00,1.01..2.0] >> >> I don't have to do it this way if there is another rounding function to >> correct the float overrun issue. >> >> >> >> On Wed, Feb 17, 2021 at 2:43 PM Francesco Ariis wrote: >> >>> Il 17 febbraio 2021 alle 14:17 Galaxy Being ha scritto: >>> > How would I install it globally? I'm not using projects, I'm just at >>> the >>> > ghci REPL. >>> >>> Most likely >>> >>> cabal install --lib Decimal >>> >>> Check what Tom has said too —F >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at redivi.com Thu Feb 18 04:29:22 2021 From: bob at redivi.com (Bob Ippolito) Date: Wed, 17 Feb 2021 20:29:22 -0800 Subject: [Haskell-beginners] import question In-Reply-To: References: <20210217185700.GA30720@extensa> <20210217204230.GA19781@extensa> Message-ID: Like others said, you'll need to install the Decimal package in order to use Data.Decimal. If you really wanted to do it with a floating point type and no dependencies you can use showFFloatAlt from Numeric to display with a specified precision. import Numeric import Text.Show main = putStrLn . showListWith (showFFloatAlt (Just 2)) [1.00, 1.01 .. 2.00] $ "" On Wed, Feb 17, 2021 at 7:42 PM Galaxy Being wrote: > As I've said, working at the ghci REPL, > > import Data.Decimal > dList :: [Decimal] > dList = [1.00,1.01..2.00] > main = print dList > > errors out > > : :76:11-17: error: > : Not in scope: type constructor or class `Decimal' > > > > On Wed, Feb 17, 2021 at 8:37 PM Bob Ippolito wrote: > >> You don't need to do any rounding if the list is already Decimal. >> >> If you wanted to format a Double with some specific decimal >> representation you could look at Numeric.showFFloatAlt or similar. >> >> import Data.Decimal >> >> dList :: [Decimal] >> dList = [1.00,1.01..2.00] >> >> main = print dList >> >> >> >> On Wed, Feb 17, 2021 at 5:27 PM Galaxy Being wrote: >> >>> I'm trying to create a list of real numbers with a two-decimal interval, >>> a la >>> >>> > [1.0,1.01,1.02,...1.99,2.00] >>> >>> however, I get the float approximation problem >>> >>> >>> [1.0,1.01,1.02,1.03,1.04,1.05,1.06,1.07,1.08,1.09,1.1,1.11,1.12,1.1300000000000001,1.1400000000000001,... >>> >>> So I attempted to compensate with >>> >>> import Data.Decimal >>> map (roundTo 2) [1.00,1.01..2.0] >>> >>> I don't have to do it this way if there is another rounding function to >>> correct the float overrun issue. >>> >>> >>> >>> On Wed, Feb 17, 2021 at 2:43 PM Francesco Ariis wrote: >>> >>>> Il 17 febbraio 2021 alle 14:17 Galaxy Being ha scritto: >>>> > How would I install it globally? I'm not using projects, I'm just at >>>> the >>>> > ghci REPL. >>>> >>>> Most likely >>>> >>>> cabal install --lib Decimal >>>> >>>> Check what Tom has said too —F >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From daniel.trstenjak at gmail.com Thu Feb 18 07:32:49 2021 From: daniel.trstenjak at gmail.com (Daniel Trstenjak) Date: Thu, 18 Feb 2021 08:32:49 +0100 Subject: [Haskell-beginners] import question In-Reply-To: References: <20210217185700.GA30720@extensa> Message-ID: <20210218073249.GA5914@octa> On Wed, Feb 17, 2021 at 02:17:32PM -0600, Galaxy Being wrote: > How would I install it globally? I'm not using projects, I'm just at the ghci REPL. Even for such small tests it's simpler to just use a cabal project: mkdir decimal-test cd decimal-test cabal init -p decimal-test -d base -d Decimal cabal repl If you need further dependencies you can then extend the 'build-depends' list in the file 'decimal-test.cabal'. Greetings, Daniel From 47dragonfyre at gmail.com Sat Feb 20 19:59:07 2021 From: 47dragonfyre at gmail.com (A. Mc.) Date: Sat, 20 Feb 2021 11:59:07 -0800 Subject: [Haskell-beginners] Using Fractional Type Message-ID: Hello, I need to create a function that does: mod (recip x) y. However, I am getting all kinds of errors with the type signature. Is there a better way to use Fractional type than needing to enable FlexibleContexts? What do I need to do to still make use of Haskell's type system, but also still be able to perform operations such as reciprocal (and division into fractions for that matter). Thanks in advance and thank you for your time. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at redivi.com Sat Feb 20 23:11:18 2021 From: bob at redivi.com (Bob Ippolito) Date: Sat, 20 Feb 2021 15:11:18 -0800 Subject: [Haskell-beginners] Using Fractional Type In-Reply-To: References: Message-ID: I think what you're looking for is the mod' function from Data.Fixed. The mod function only works with Integral types, FlexibleContexts wouldn't be helpful for this. On Sat, Feb 20, 2021 at 12:00 PM A. Mc. <47dragonfyre at gmail.com> wrote: > Hello, > > I need to create a function that does: mod (recip x) y. However, I am > getting all kinds of errors with the type signature. Is there a better way > to use Fractional type than needing to enable FlexibleContexts? What do I > need to do to still make use of Haskell's type system, but also still be > able to perform operations such as reciprocal (and division into fractions > for that matter). > > Thanks in advance and thank you for your time. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dj112358 at outlook.com Sun Feb 21 08:41:52 2021 From: dj112358 at outlook.com (David James) Date: Sun, 21 Feb 2021 08:41:52 +0000 Subject: [Haskell-beginners] Using Fractional Type In-Reply-To: References: , Message-ID: Also, I wonder if you’re typing: > 5 mod 2 This does give a FlexibleContexts error. You should type either: > mod 5 2 or > 5 `mod` 2 (or, using mod’ as suggested): > 5.5 `mod'` 1.3 You can read about prefix and infix notation here. David. From: Bob Ippolito Sent: 20 February 2021 23:11 To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell Subject: Re: [Haskell-beginners] Using Fractional Type I think what you're looking for is the mod' function from Data.Fixed. The mod function only works with Integral types, FlexibleContexts wouldn't be helpful for this. On Sat, Feb 20, 2021 at 12:00 PM A. Mc. <47dragonfyre at gmail.com> wrote: Hello, I need to create a function that does: mod (recip x) y. However, I am getting all kinds of errors with the type signature. Is there a better way to use Fractional type than needing to enable FlexibleContexts? What do I need to do to still make use of Haskell's type system, but also still be able to perform operations such as reciprocal (and division into fractions for that matter). Thanks in advance and thank you for your time. _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From borgauf at gmail.com Thu Feb 25 23:23:46 2021 From: borgauf at gmail.com (Galaxy Being) Date: Thu, 25 Feb 2021 17:23:46 -0600 Subject: [Haskell-beginners] Non-exhaustive patterns in function error Message-ID: I have this intersect1 :: ([a],[a]) -> [a] intersect1 (s,[]) = [] interesct1 (s,t:ts) | elem t s = t : intersect1 (s,ts) | otherwise = intersect1 (s,ts) and when I try this intersect1 ([1,2],[1,2,3]) I get the error Non-exhaustive patterns in function intersect1 Not sure what's wrong with this. LB -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Thu Feb 25 23:45:41 2021 From: fa-ml at ariis.it (Francesco Ariis) Date: Fri, 26 Feb 2021 00:45:41 +0100 Subject: [Haskell-beginners] Non-exhaustive patterns in function error In-Reply-To: References: Message-ID: <20210225234541.GA31267@extensa> Il 25 febbraio 2021 alle 17:23 Galaxy Being ha scritto: > I have this > > intersect1 :: ([a],[a]) -> [a] > intersect1 (s,[]) = [] > interesct1 (s,t:ts) | elem t s = t : intersect1 (s,ts) > | otherwise = intersect1 (s,ts) > > and when I try this > > intersect1 ([1,2],[1,2,3]) > > I get the error > > Non-exhaustive patterns in function intersect1 > > Not sure what's wrong with this. Pattern (_,[]) is not matched! From bob at redivi.com Thu Feb 25 23:52:30 2021 From: bob at redivi.com (Bob Ippolito) Date: Thu, 25 Feb 2021 15:52:30 -0800 Subject: [Haskell-beginners] Non-exhaustive patterns in function error In-Reply-To: References: Message-ID: It's the typo. Note that you'll also need an Eq a typeclass constraint for this type signature to be correct (which is the next error you'd get) -- underscores for emphasis inter_se_ct1 inter_es_ct1 On Thu, Feb 25, 2021 at 3:24 PM Galaxy Being wrote: > I have this > > intersect1 :: ([a],[a]) -> [a] > intersect1 (s,[]) = [] > interesct1 (s,t:ts) | elem t s = t : intersect1 (s,ts) > | otherwise = intersect1 (s,ts) > > and when I try this > > intersect1 ([1,2],[1,2,3]) > > I get the error > > Non-exhaustive patterns in function intersect1 > > Not sure what's wrong with this. > > LB > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From borgauf at gmail.com Fri Feb 26 02:00:41 2021 From: borgauf at gmail.com (Galaxy Being) Date: Thu, 25 Feb 2021 20:00:41 -0600 Subject: [Haskell-beginners] Non-exhaustive patterns in function error In-Reply-To: References: Message-ID: How embarrassing... intersect1 :: (Eq a) => ([a],[a]) -> [a] On Thu, Feb 25, 2021 at 5:53 PM Bob Ippolito wrote: > It's the typo. Note that you'll also need an Eq a typeclass constraint for > this type signature to be correct (which is the next error you'd get) > > -- underscores for emphasis > inter_se_ct1 > inter_es_ct1 > > > On Thu, Feb 25, 2021 at 3:24 PM Galaxy Being wrote: > >> I have this >> >> intersect1 :: ([a],[a]) -> [a] >> intersect1 (s,[]) = [] >> interesct1 (s,t:ts) | elem t s = t : intersect1 (s,ts) >> | otherwise = intersect1 (s,ts) >> >> and when I try this >> >> intersect1 ([1,2],[1,2,3]) >> >> I get the error >> >> Non-exhaustive patterns in function intersect1 >> >> Not sure what's wrong with this. >> >> LB >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From brodyberg at gmail.com Fri Feb 26 03:51:41 2021 From: brodyberg at gmail.com (Brody Berg) Date: Thu, 25 Feb 2021 19:51:41 -0800 Subject: [Haskell-beginners] Non-exhaustive patterns in function error In-Reply-To: References: Message-ID: Don’t worry about it. We’ve all been there. On Thu, Feb 25, 2021 at 18:01 Galaxy Being wrote: > How embarrassing... > > intersect1 :: (Eq a) => ([a],[a]) -> [a] > > > On Thu, Feb 25, 2021 at 5:53 PM Bob Ippolito wrote: > >> It's the typo. Note that you'll also need an Eq a typeclass constraint >> for this type signature to be correct (which is the next error you'd get) >> >> -- underscores for emphasis >> inter_se_ct1 >> inter_es_ct1 >> >> >> On Thu, Feb 25, 2021 at 3:24 PM Galaxy Being wrote: >> >>> I have this >>> >>> intersect1 :: ([a],[a]) -> [a] >>> intersect1 (s,[]) = [] >>> interesct1 (s,t:ts) | elem t s = t : intersect1 (s,ts) >>> | otherwise = intersect1 (s,ts) >>> >>> and when I try this >>> >>> intersect1 ([1,2],[1,2,3]) >>> >>> I get the error >>> >>> Non-exhaustive patterns in function intersect1 >>> >>> Not sure what's wrong with this. >>> >>> LB >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From borgauf at gmail.com Fri Feb 26 18:28:30 2021 From: borgauf at gmail.com (Galaxy Being) Date: Fri, 26 Feb 2021 12:28:30 -0600 Subject: [Haskell-beginners] Closure clear-up? Message-ID: >From my moving-target understanding of closures, I'm guessing this has a closure let succ = add 1 add x = xadder where xadder y = x + y in succ 3 Now, can someone explain in words how the closure system is at work here? I see that the add 1 is being "baked in". Do we say this is a closure on add 1? (Closure wording is confusing.) The enclosing scope of add contains 1; however, xadder is what succ ultimately becomes, which has 1 in its scope in that when xadder is defined, the x argument will be the 1 of add 1. Or am I missing something? Researching closures vis-a-vis Haskell, I've seen the argument that, - no, Haskell doesn't have closures, - yes, Haskell is lazy, *everything* can be seen as a closure, as even a value can be seen as a function without argument waiting to be evaluated (and so capturing its environment until it gets evaluated). This was taken from an older Haskell textbook (*Introduction to Functional Programming Systems Using Haskell *by Davie). LB -------------- next part -------------- An HTML attachment was scrubbed... URL: From stuebinm at disroot.org Sat Feb 27 18:00:27 2021 From: stuebinm at disroot.org (stuebinm) Date: Sat, 27 Feb 2021 19:00:27 +0100 Subject: [Haskell-beginners] Bounded number types? Message-ID: <004ce73c-486d-be27-bccc-68a7f00aaf3a@disroot.org> Hi all, I'm wondering: is there any type that represents e.g. a floating point value that is guaranteed to be within some interval (e.g. [0,1]?). My practical use-case would be that I'm reading in input data from json, which may be ill-behaved — obviously I could just manually check, and then keep track of which numbers in which record fields are within which intervals, but coming from less strongly typed programming languages I wonder if there would be a "typed" way to do this, too. -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_0x695C841098BECF1D.asc Type: application/pgp-keys Size: 3131 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 840 bytes Desc: OpenPGP digital signature URL: From 47dragonfyre at gmail.com Sun Feb 28 02:07:21 2021 From: 47dragonfyre at gmail.com (A. Mc.) Date: Sat, 27 Feb 2021 18:07:21 -0800 Subject: [Haskell-beginners] Creating a Triple List from a List Message-ID: Hello, What is the best way to take: [1, 2, 3, 4 ] And convert it to: [ [ [ 1 ], [ 2 ] ], [ [3]. [4] ] ] so that each member pair is: [ [1], [2] ] roughly analogous to a 1x2 vector? Thanks in advance and thank you for your time. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Sun Feb 28 02:29:27 2021 From: fa-ml at ariis.it (Francesco Ariis) Date: Sun, 28 Feb 2021 03:29:27 +0100 Subject: [Haskell-beginners] Creating a Triple List from a List In-Reply-To: References: Message-ID: <20210228022927.GA30216@extensa> Il 27 febbraio 2021 alle 18:07 A. Mc. ha scritto: > Hello, > > What is the best way to take: > [1, 2, 3, 4 ] > > And convert it to: > > [ [ [ 1 ], [ 2 ] ], [ [3]. [4] ] ] > > so that each member pair is: > > [ [1], [2] ] > > roughly analogous to a 1x2 vector? A 1×2 vector would be > [[1 2], [3, 4]] am I wrong? If so, a quick and dirty solution could be d2 :: [a] -> [[a]] d2 [] = [] d2 [a] = error "odd element" d2 as = let (is, es) = splitAt 2 as in is : d2 es -- λ> d2 [1..6] -- [[1,2],[3,4],[5,6]]