hask | Haskell language features and standard libraries | Functional Programming library
kandi X-RAY | hask Summary
kandi X-RAY | hask Summary
Hask is a pure-Python, zero-dependencies library that mimics most of the core language tools from Haskell, including:.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Analyze node .
- Build signature argument .
- Return True if value matches pattern .
- Build an ADT type .
- Create a data constant .
- Unify two types .
- Create a type constant .
- Compares two lists .
- Unify two types .
- Return type of object .
hask Key Features
hask Examples and Code Snippets
Community Discussions
Trending Discussions on hask
QUESTION
I understand that many of the names in Haskell are inspired by category theory terminology, and I'm trying to understand exactly where the analogy begins and ends.
The CategoryHask
I already know that Hask
is not (necessarily) a category due to some technical details about strictness/laziness and seq
, but let's put that aside for now. For clarity,
- The objects of
Hask
are concrete types, that is, types of kind*
. This includes function types likeInt -> [Char]
, but not anything that requires a type parameter likeMaybe :: * -> *
. However, the concrete typeMaybe Int :: *
belongs toHask
. Type constructors / polymorphic functions are more like natural transformations (or other more general maps fromHask
to itself), rather than morphisms. - The morphisms of
Hask
are Haskell functions. For two concrete typesA
andB
, the hom-setHom(A,B)
is the set of functions with signatureA -> B
. - Function composition is given by
f . g
. If we are worried about strictness, we might redefine composition to be strict or be careful about defining equivalence classes of functions.
Functor
s are Endofunctors in Hask
I don't think the technicalities above have anything to do with my confusion below. I think I understand it means to say that every instance of Functor
is an endofunctor in the category Hask
. Namely, if we have
ANSWER
Answered 2021-Apr-21 at 06:31You're right that Konst m
isn't quite a constant functor from a category-theory standpoint. But it's very closely related to one!
QUESTION
I am trying to read a txt file with this format (heading not included):
...ANSWER
Answered 2021-Mar-16 at 17:00From what you have described it looks like you also want to break your string when a line ends. To do this add a carriage return as one of delimiting cases in the following manner-
QUESTION
I'm new to Haskell and tinkering with a few examples from Stephen Diehl's What I Wish I Knew When Learning Haskell.
I'm stuck on this monad transformer example : original code.
Even after simplifying the code to the bare minimum, I've failed to zero in on the cause of the error. I've also looked at other questions here on SO that appear similar but the cause of the problem seems to be different.
Here's the simplified code:
...ANSWER
Answered 2020-Dec-16 at 13:50You can not print a value of type Eval Int
since that is defined as ReaderT Env Maybe Int
. Printing a value in that type would essentially amount to printing a function Env -> Maybe Int
, and functions can't be printed.
Consider calling the function using
QUESTION
Is there any general functor (not limited to endofunctor) usage in programming?
I understand the reason endofunctor employed is to make the structure simple like monoid or monad.
I also understand ultimately, all the value is settled down to a category of a programming language (such as Hask), but what I'm talking about here is endofunctor between the same category of Strings, Numbers, Booleans, or Functions.
Related questions:
...ANSWER
Answered 2020-Aug-25 at 12:25First, yes.
For example, we all know that a monoid can be defined to be a single-object category with
- arrows to be elements
- the single object has no meaning
- composition to be operator (
(<>)
in Haskell) - id arrow to be the identity (
mempty
in Haskell).
And a homomorphism between two monoids becomes a functor between two categories in this sense.
Now, say, type A
and B
are both monoids; A functor between them is just a homomorphic function f :: A -> B
that maps each A
to B
, preserving the composition.
But, wait,
f :: A -> B
is not even aFunctor
(note that I use the monospaced typeface here)!
No, it is not a Functor
in Haskell, but it still is a functor in mathematical sense.
So, to emphasize, I state it again: "Non-endo" functors ARE used in programming, and probably even more often than endofunctors.
The point here is that category theory is a highly abstract theory - It provides notions for abstracting concrete objects. We can define these notions to mean different things in different contexts.
And Hask (or Set, or subcategories of Set) is just one of these infinite definitions, which makes
- arrows to be functions
- objects to be types (or, sets)
- composition to be function composition
(.)
- id arrow to be the
id
function.
Compare this "categorical universe" definition with the "categorical monoid" definition above - congrats, you've known two different takes on categories now!
To conclude, remember that category theory itself is just some abstractions. Abstractions themselves have no meaning and no use at all. We connect them to real things, and only in this way they can bring us convenience. Understand abstract concepts through concrete examples, but NEVER simplify these concepts themselves to anything concrete (Like, never simplify functors to merely the functors between "categorical universes" (e.g. Hask, Set, etc)!).
P.S. If you ask "Is there a functor that sends Hask to another category in Haskell?" then the answer can be yes or no. For example, you can define a category Hask * Hask to contain any two types' cartesian product, and a functor
data Diag a = Diag a a
,fmap f x = Diag (f x) (f x)
that sends each typeA
to its squareA * A
. However, Hask * Hask is still a subcategory of Hask, so we may say this is an endofunctor too.
QUESTION
I have a section in an index page that lists posts from the posts/* directory. What I would like is to have another section that lists posts from a bibs/* directory.
So, it would look something like:
...ANSWER
Answered 2020-Aug-13 at 16:54You can use the field
and <>
combinators to extend a Context
(homeCtx
in this case) with the contents of the lists under some tags. Here, I've renamed the tags body
and body2
to posts
and bibs
because body
is a tag with a special meaning in Hakyll. Remember to also rename the tags in templates/index.html
.
QUESTION
Control.Category.Constrained
is a very interesting project that presents the class for cartesian closed categories - Curry
.
Yet, I do not see why we think of all cartesian closed categories which allow curry
and uncurry
(Hom(X * Y, Z) ≅ Hom(X, Z^Y)
in terms of category theory). Wikipedia says that such property holds only for locally small cartesian closed categories. Under this post many people suggest that Hask itself is not locally small (on the other hand, everyone says that Hask is not a cartesian closed category, which I reckon to be pure and uninteresting formalism).
In this post on Math.SE speaks on assuming all categories are locally small. But it is given from a mathematical point of view where we discuss properties. I would like to know why we decided to concentrate on curry
and uncurry
as Curry
’s methods. Is it because pretty much everyone who knows Haskell also knows these functions? Or is there any other reason?
ANSWER
Answered 2020-Jul-20 at 14:50I would like to know why we decided to concentrate on
curry
anduncurry
asCurry
’s methods. Is it because pretty much everyone who knows Haskell also knows these functions?
As the library author I can answer that with confidence and the answer is yes: it is because curry
and uncurry
are well-established part of the Haskell vernacular. constrained-categories
was never intended to radically change Haskell and/or make it more mathematically solid in some sense, but rather to subtly generalise the existing class hierarchies – mostly to allow defining functors etc. that couldn't be given Prelude.Functor
instances.
Whether Curry
could be formalised in terms of local smallness I frankly don't know. I'm also not sure whether that and other “maths foundations” aspects can even be meaningfully discussed in the context of a Haskell library. Somewhat off-topic rant ahead It's just a fact that Haskell is a non-total language, and yes, that means just about any axiom can be thwarted by some undefined
attack. But I also don't really see that as a problem. Many people seem to think of Haskell as a sort of uncanny valley: too restrictive for use in real-world applications, yet nothing can be proved properly. I see it exactly the other way around: Haskell has a sufficiently powerful type system to be able to express the mathematical ideas that are useful for real-world applications, without getting its value semantics caught up too deep in the underlying foundations to be practical to actually use in the real world. (I.e., you don't constantly spend weeks proving some “obviously it's true that...” theorem. I'm looking at you, Coq...)
Instead of writing 100% rigorous proofs, we narrow down the types as best as possible and then use QuickCheck to see whether something typically works as the maths would demand.
Don't get me wrong, I think formalising the foundations is important too and dependently-typed total languages are great, but all that is somewhat missing the point of where Haskell's potential really lies. At least it's not where I aim my Haskell development, including constrained-categories
. If somebody who's deeper into the pure maths wants to chime in, I'm delighted to hear about it.
QUESTION
I've been reading the book "What I wish I knew when learning Haskell" and I stopped on this example:
...ANSWER
Answered 2020-Jun-08 at 09:00(x,y)
is already a concrete tuple type, containing two concrete (albeit unknown) types x
and y
. A functor, or bifunctor, meanwhile is supposed to be parametric, i.e. in case of the tuple instance you'd want the contained types to be left open as parameters, which are then filled in with various different concrete types when the methods are used.
I.e., you basically want a type-level lambda
QUESTION
I am looking for the reverse of this essentially, and am going out of my mind.
Something that reverses the arguments of the below to check of any element of a list is in a string.
Instead of:
any (isInfixOf "Hask") ["I am", "new to", "Haskell"]
I need:
any (isInfixOf ["I am", "new to", "Haskell"]) "I am new to"
Any help appreciated!
...ANSWER
Answered 2020-May-16 at 09:58You can write this with a lambda expression as:
QUESTION
I am trying to write an evaluator which executes a simple if-block of code. The only two conditions that I'm interested in at the moment is when the condition to enter the block is true or false or if the condition is a relational expression.
The former pattern works fine and it makes sense to me in the implementation of it.
...ANSWER
Answered 2020-May-13 at 21:54So my issue was not knowing how to evaluate RBinary
because it requires three arguments but we are only given one, cond
. I played around in GHCI and figured out that I could just treat cond
as a three argument expression if I pass it to eval
instead of evalCond
. This evaluates correctly and as an added benefit, I can remove evalCond
though I will keep it if it becomes necessary later on.
The code to fix it was:
QUESTION
I'm writing a simple language in Haskell but I'm having an issue in evaluating arithmetic and relational expressions. At first I wrote one evaluation function then I recognised that I would need separate functions to evaluate each aspect of my language. So I have an arithmetic evaluation function, a relational evaluation function, and then a general evaluation functions.
The issue arises from actually producing something to work with and I think this comes from not being able to relate my other eval functions back to my main eval function. However I'm not sure if I'm approaching the evaluation incorrectly or not. I believe that perhaps a function like 'foldl1' would more useful to implement into the evaluation. I first learned about this function from the Write Yourself A Scheme in 48 Hours Wikibook and it seems like it's infinitely more useful than evaluating each possible expression. I'm not sure how this would implementable in my current code as it stands unless I had a function for each expression. For example if I had an expression like "1 + 1", my current parser parses this as "1 Add 1" but if I were to go with foldl1, I could have a function that gets each part this expression and "folds" the operator over the arguments. Even if I were to merge my current evaluation functions with the idea of foldl1, I still foresee the problem in evaluating anything meaningful from it that isn't just an integer or a string.
Any direction or help would be appreciated.
Below I have included by datatypse and my evaluation functions:
...ANSWER
Answered 2020-May-04 at 18:41I'm not sure using foldl1
would help you much here. In the "Write Yourself a Scheme" wikibook, the foldl1
function is used for the very specific purpose of applying "binary" functions like +
and -
to lists of arguments that might be of length > 2. In Lisp, (+ 1 2 3)
means the same thing as the Haskell expression:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install hask
git clone https://github.com/billpmurphy/hask
python setup.py install
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