lyah | learn you a haskell for great good 中文版 | Functional Programming library
kandi X-RAY | lyah Summary
kandi X-RAY | lyah Summary
learn you a haskell for great good 中文版
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Generate steps for the step
- Clears an element .
- given a subject file returns read one
- Text helper function
- Generate a recipe .
- Add line numbers to list numbers
- Prepare Recipes
- Enables text selection
- Loads a recipe for the given element .
- parse DOM file
lyah Key Features
lyah Examples and Code Snippets
Community Discussions
Trending Discussions on lyah
QUESTION
I'd like to understand how to access fields of custom data types without using the record syntax. In LYAH it is proposed to do it like this:
...ANSWER
Answered 2021-Jun-25 at 13:25You forgot to add the type parameter to Tree
in your function's type signature
QUESTION
I just started on Haskell and really love the language! Was looking for some installation help.
I just finished CIS194 and most of the excellent LYAH book. I am currently doing the fp-course recommended here: https://github.com/bitemyapp/fp-course
My issue is that i've done of my work on a mac os laptop up to this point, and now want to do a haskell installation on my windows desktop to work on my larger and more comfortable home setup; however i've struggled to find a method to do a "clean" installation. The haskell platform keeps recommending choclatey which doesn't seem to offer me a choice to change the download location. My issue is that i use a small SSD for my OS drive, and have a large 2TB secondary drive where i would like the installation to go instead.
My other point of confusion is that some people seem to vehemently recommend a stack installation instead of the haskell platform installation; whilst others say it doesn't matter. I'm a beginner so I doubt it matters to me but the haskell platform and choclatey were extremely frustrating as after I installed them, not only was I not able to find a beginner friendly way to change the installation directory, deleting packages/haskell entirely was extremely obtuse and hard to find resources for.
My concern is that over time, this will take a significant amount of space on my smaller system drive, forcing me to reformat again. I'm not sure if a Stack installation will be any better in this regard but I'm hoping for an installation that lets me choose exactly where all the files go.
Many posts outlined an uninstaller that should have come with the haskell platform, but it did not for me and was not shown in my add or remove programs so i had to resort to simply reformatting and am now looking for help before jumping back in (to hopefully avoid doing this again).
In summary, could I have help with doing an installation on a non-home drive, that is very easily removed, with clear knowledge of exactly where all the haskell files are, on a Windows 10 machine? Would really appreciate any help with this!
...ANSWER
Answered 2021-Jun-22 at 09:26My advice, use stack
for installing GHC and for project and dependency management. All Haskell's dependencies are under the stack
folder (global) and .stack-work
folder (per project), making it clean to remove and check for storage size: Just delete these folders and no trace of Haskell will reamain in your system. (Notice, that the path to the folders are system dependent, so check the documentation for windows installation)
The way stack
helps you to keep dependencies/storage under control is by using snapshots
. This is a fixed set of library version. For example:
- lts-18.0 uses compiler version
ghc-8.10.4
. In the link you can see the version of each library. - As long as you use the same
lts
all along your global configuration and projects configuration,stack
will reuse dependencies between projects, so you avoid downloading the same library with different version and different compilers too.
The problem with stack
is that a miss-use of it, can lead to the storage problem you are afraid of. So, before using stack
be sure you:
Read the user guide. Most question asked in this site about
stack
are explicitly resolved in the user guide.Again, read the whole user guide... I'm serious about this. If you come from python-ish enviroment in which
pip install
solves your problems, you'll find a lot of troubles usingstack
due to project-oriented dependencies over global dependenciesBe sure you understand what a
snapshot
(a.k.a.lts
) is, and how to configure it, otherwise, you'll end up with many different version of the compiler installed in your computer (hence, tons of storage wasted).The differences between the
stack.yaml
andproject.yaml
.If you have a concrete question about
stack
come back here a post it. Please avoid generic questions like Can anyone explain stack?, it is prefered somthing specific and direct to the point. ex: what is the difference between lts-17 and lts-16?
QUESTION
I'm trying to implement a function that adds an element (a type) to a list of this type to an existing created datatype. Since Haskell data variable are immutable, I know that you have to create a new data with the same characteristic as the first one and add onto it, but I can seem to make ghci compile my program and make it do what I'm trying to accomplish.
Here is my code and the function which should add a contact to a list of already existing contact addContact
which I'm been trying to work on:
ANSWER
Answered 2021-Feb-15 at 03:05There are multiple issues in your code. The fixed version of the addContact function:
QUESTION
I have created the type Contact, and I'm trying to create a function that takes 4 parameters (First Name, Last Name, Phone and State) and creates a contact and adds it to a list of existing contact.
...ANSWER
Answered 2021-Feb-14 at 18:53Contact
is not the type constructor, Contact
is just an alias for (Person, State)
, so a 2-tuple, hence (,)
is the data constructor:
QUESTION
Question is in bold at the bottom.
LYAH gives this example of using the do
notation with the Writer
monad
ANSWER
Answered 2020-Oct-06 at 15:17The equivalent re-write is further
QUESTION
Functional Programming in C++, at page 214, with reference to an expected
monad which is the same as Haskell's Either
, reads
[...] as soon as any of the functions you're binding to returns an error, the execution will stop and return that error to the caller.
Then, in a caption just below, it reads
If you call
mbind
[equivalent to Haskell's>>=
] on anexpected
that contains an error,,mbind
won't even invoke the transformation function; it will just forward that error to the result.
which seems to "adjust" what was written earlier. (I'm pretty sure that either LYAH or RWH underlines somewhere that there's no short-circuiting; if you remember where, please, remind me about it.)
Indeed, my understanding, from Haskell, is that in a chain of monadic bindings, all of the bindings happen for real; then what they do with the function passed to them as a second argument, is up to the specific monad.
In the case of Maybe
and Either
, when the bindings are passed a Nothing
or Left x
argument, then the second argument is ignored.
Still, in this specific two cases, I wonder if there's a performance penalty in doing something like this
...ANSWER
Answered 2020-Sep-17 at 19:32Consider the following expression:
QUESTION
I'm relatively new to Haskell, and have been trying to learn it for the past few weeks, but have been stuck on Filters and Predicates, which I was hoping to get help with understanding.
I have come across a problem whereby I have a list of tuples. Each tuple consists of a (songName, songArtist, saleQty)
and am required to remove a tuple from that list based on the user inputting the songName and SongArtist.
When returning the results, I understand I can remove a tuple by using the Filter
function when returning the results. I have been doing some reading on it using LYAH. Its taught me that I have to use a Predicate (which is another function) to filter through my results. This has caught me off guard as I learnt a Filter
function has type (a -> Bool) -> [a] -> [a]
, which means my input for the Filter
needs to to be a Boolean and my output for my Predicate needs to be Boolean so it can be fed to the Filter
.
This is a problem, as to filter my results from the list I need to input the songName and songArtist (both of which are String types) to the predicate when recursively going through the results, and output the songName and songArtist to the Filter
to let it know which exact tuple needs to be removed from the list.
Am I going about this the wrong way or is there a better way I could go about this?
...ANSWER
Answered 2020-Aug-06 at 16:45I learnt a Filter function has type
(a -> Bool) -> [a] -> [a]
The filter :: (a -> Bool) -> [a] -> [a]
takes two parameters, a predicate with signature a -> Bool
, and a list of items, and it returns a list of items that satisfy the predicate. So the predicate is the first parameter.
which means my input for the
Filter
needs to to be aBoolean
.
No the first parameter has type a -> Bool
, so it is a function that maps an item a
to a Bool
, so a predicate.
You can for example create a function that checks if both the songName
and songTitle
match with:
QUESTION
From LYAH I understand that the do
notation is just syntactic sugar for monadic style; and from the wikibook I read more or less the same; so my understanding is that there can't be any do
notation if there's no Monad
instance.
Yet I read this definition of the Functor
instance of the IO
type ctor.
ANSWER
Answered 2020-Jul-22 at 22:46A type having an instance of Monad
implies it must have a definition of Functor
(and Applicative
), but that doesn’t mean the Functor
instance must be defined “first”, only that both instances must exist. As long as the method implementations aren’t defined in terms of each other circularly, there’s no problem.
In fact, it often makes sense to implement Monad
for a type first, then define Applicative
and Functor
mechanically in terms of Monad
operations, because Monad
is more powerful, so the other instances are just restrictions of the Monad
instance:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install lyah
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page