Line segments oriented by an angle and orthogonal design concepts led to an engineering-grade draft of a language I designed in Haskell. It defines angles with high-level forms in the geometric domain, showing greater insight and skill for related domain languages. https://lnkd.in/epRDxnPs #haskell #functionalprogramming #math #softwareengineering
Tobias Briones’ Post
More Relevant Posts
-
In his new blog post “Extending destination-passing style programming to arbitrary data types in Linear Haskell”, Thomas BAGREL shows us some of the things that can be done if we extend a pure language with destinations (which he did for Haskell) https://hubs.ly/Q02nyLs80
Extending destination-passing style programming to arbitrary data types in Linear Haskell
tweag.io
To view or add a comment, sign in
-
💥 Ollama-haskell ollama-haskell is an unofficial Haskell binding for Ollama, similar to ollama-python. This library allows you to interact with Ollama, a tool that lets you run large language models (LLMs) locally, from within your Haskell projects. 👉 https://lnkd.in/d_3akM9f #haskell #machinelearning
To view or add a comment, sign in
-
Introducing minbpe-hs - a port of Andrej Karpathy's concise byte-level byte pair encoding (BPE) implementation, minbpe, to Haskell. Given its recursive nature, BPE lends itself naturally to functional programming, and the objective of this repository is to offer an alternative functional formulation of it that is orthogonal to typical implementations in imperative languages such as Python or Rust to aid learners in gaining a firmer grasp on BPE by viewing it through a different lens. Please refer to the GitHub repository below for more information. #haskell #tokenizer #bpe #bytepairencoding #llm
GitHub - BobMcDear/minbpe-hs: Byte-level byte pair encoding (BPE) in Haskell
github.com
To view or add a comment, sign in
-
What's with the "ternary operators are just syntactic sugar for if else" trend? I normally don't mind uninformed trendy hot takes, but this one is simply moronic. They are not the same thing. A ternary operator is an expression, it returns a value, you only have to consider that it's something that returned a value, just like if you had moved the logic to another function, an if else is made of two blocks of statements, where side effects will (not may, WILL) happen, and you need to keep track of them. It's pattern matching for booleans. Matter of fact, Haskell, OCaml and F#, languages where statements are disencouraged or straight away can't happen, have if/else be an expression, so you do: let bigger = if a < b then b else a In Haskell, a language designed for correctness, where it's impossible to write an if else as you would in C#, you have a ternary operator. They are not the same thing, they operate in two different paradigms.
To view or add a comment, sign in
-
While working through [100 Rust Exercises](https://lnkd.in/g7-uHkDC), I ran across this article: [Parse, don't validate by Alexis King](https://lnkd.in/gajm3_qp) The article describes solving input validation problems at the Type checking stage, when using strongly typed languages like Rust or Haskell. It is well worth a read for anyone concerned about writing truly secure software, or working on data pipelines. This has me thinking about ways to use Pandera to parse Pandas dataframes in my python data pipelines, adapting the underlying principles to the dynamically typed realm, to improve the quality and reliability of those pipelines.
Parse, don’t validate
lexi-lambda.github.io
To view or add a comment, sign in
-
a full-stack Haskell developer with some knowledge of JavaScript, TypeScript, Nix, and Bash excited about math and creating games in Haskell :)
FUNCTORS, APPLICATIVE FUNCTORS, AND MONADS I think that every haskeller should try to explain what functors, applicative functors, and monads are. In this post I’d like to fulfil my duty as a haskeller. Here’s my attempt to explain what they are particularly in Haskell based on my understanding of them (or a delusion thereof). These functional idioms incrementally introduce some amount of imperativity into Haskell (which is fully declarative without them). The following should be considered to be true when a focused structure is used as some functional idiom, that is, when some methods of a functional idiom (<$>, <*>, =<<, etc.) are applied to the structure or it is created using the do notation. FUNCTOR The functor introduces a notion of a container for values on which the fmap (<$>) method can be used, but not imperativity yet. The container is fully determined initially and cannot be changed. Such a container has the following properties: fmap id = id It claims that if values of a functor are not changed, then the functor is not changed at all because fmap (<$>) is a combinator (so are <*> and =<<). fmap (g . f) = fmap g . fmap f It claims that the structure of the functor cannot be changed, only its values. For instance, the length of the list [1, 2, 3] cannot be changed and (Just 1) cannot become Nothing. Therefore, the functor is a container only values of which can be changed, not its structure. APPLICATIVE FUNCTOR The applicative functor is a functor in which the notion of a container becomes rather the one of a context. A final context is determined by both a function’s context and a structure’s context and can be changed. It introduces a notion of imperativity of the context regardless of its values. At least being an applicative functor is required to do chaining, for instance, print “a” *> print “b” *> print “c”. Otherwise, it is not possible. It deffers from a functor by having its function in a context. This fact generalises a functor for several arguments. Applying a function in a context to a context yields another function in a context till all the arguments are supplied. MONAD The monad is the functor in which a final context is determined by a function’s context, a context, and also by the value inside the context, that is, the value returned by the context available inside the function. SUMMARY The functor is declarative, the applicative functor is imperative, and the monad is very imperative. The structure of a functor is determined initially and cannot be changed. The context of an applicative functor is determined by a function and a context regardless of its values of the context and can be changed. The context of a monad is determined by a function, a context, and the value inside the context and can be changed. I hope very much that this post will be usefull for someone. Don’t hesitate to point out my errors and mistakes or suggest corrections if I’m wrong. #haskell #categoryTheory #functor #monad
To view or add a comment, sign in
-
I just started my journey with #AdventOfCode in #Haskell. 🚀 A major aspect of Haskell is pattern matching, and the way it can be used for function input is fundamentally different from most popular languages. 🔍 For day 1 of Advent of Code 2017, you need to calculate the value of a number by summing up the digits that equal their successors. For example, the value of 1122 is 3 because 1 appears twice in a row, as does 2, and the sum of both is 3. 📅 In Haskell to solve this puzzle you want to transform a list of digits into a list of tuples where the first item is said digit and the second its successor so you can evaluate if they match. 💡 That function is a great example to demonstrate pattern matching in Haskell: 𝚒𝚝𝚎𝚛𝚊𝚝𝚎𝙰𝚗𝚍𝙿𝚎𝚎𝚔 :: [𝙸𝚗𝚝] -> [(𝙸𝚗𝚝, 𝙼𝚊𝚢𝚋𝚎 𝙸𝚗𝚝)] 𝚒𝚝𝚎𝚛𝚊𝚝𝚎𝙰𝚗𝚍𝙿𝚎𝚎𝚔 [] = [] 𝚒𝚝𝚎𝚛𝚊𝚝𝚎𝙰𝚗𝚍𝙿𝚎𝚎𝚔 [𝚡] = [(𝚡, 𝙽𝚘𝚝𝚑𝚒𝚗𝚐)] 𝚒𝚝𝚎𝚛𝚊𝚝𝚎𝙰𝚗𝚍𝙿𝚎𝚎𝚔 [𝚡, 𝚢] = [(𝚡, 𝙹𝚞𝚜𝚝 𝚢)] 𝚒𝚝𝚎𝚛𝚊𝚝𝚎𝙰𝚗𝚍𝙿𝚎𝚎𝚔 (𝚡:𝚢:𝚡𝚜) = (𝚡, 𝙹𝚞𝚜𝚝 𝚢) : 𝚒𝚝𝚎𝚛𝚊𝚝𝚎𝙰𝚗𝚍𝙿𝚎𝚎𝚔 (𝚢:𝚡𝚜) This code defines a function iterateAndPeek. The first line is optional and represents its signature: It takes a list of Int and returns a list of tuples - or pairs, because it has two items - of which the first is an Int and the second a Maybe Int, meaning it can be Nothing or an Int wrapped in a Just. 📝 The other lines describe different input patterns and what is returned in each case. For an empty list, an empty list is returned. If the list contains only one item, a tuple of that item and Nothing is returned. If the list contains exactly two items, a tuple of the first item and "Just" the second item is returned. If the list is longer, it is deconstructed as - the first item in the list x - the second item y - and the "tail," which is the rest and is named xs. This final branch is recursive, it will return a list with x and Just y and append the result of calling itself with x removed from the head of the list. 🔄 What I love about this approach in Haskell is that you really know what to expect here. In contrast, in most non-functional or general-purpose programming languages, there's just a function body with arbitrary code, and the code depends very much on the preferences of the programmer. It could contain guard clauses, a switch statement, nested if branches, a lot of local variables, and many different or just one return statement. In a conventional programming language (if I may call it that) every function body is different and there's a multitude of ways to express the same thing. So you need to read the code very carefully to be sure to understand it. Haskell makes it very clear on the first look if all edge cases are considered and what the respected intend is, and the recursive approach, in my opinion, is more concise and leaner than the average loop-based solution. 🎯 Here's the complete code: https://lnkd.in/eDWN3WCX #Coding #FunctionalProgramming #PatternMatching
To view or add a comment, sign in
-
The Power of Mathematics in Programming: How Haskell's Foundations Lead to Simpler, Less Error-Prone Code 1. Haskell Example: The Haskell code leverages its strong mathematical underpinnings, particularly from category theory. The use of the Maybe monad demonstrates Haskell's capability to handle operations that might fail, using a compact and expressive syntax that naturally combines functors with applicatives in a mathematical way. The code is succinct and elegantly handles potential failure points in computations, showcasing Haskell's strengths in dealing with complex operations concisely. import Control.Applicative safeDivide :: Int -> Int -> Maybe Int safeDivide _ 0 = Nothing safeDivide x y = Just (x `div` y) safeSquareRoot :: Int -> Maybe Int safeSquareRoot x | x < 0 = Nothing | otherwise = Just (round . sqrt $ fromIntegral x) complexOperation :: Int -> Int -> Maybe Int complexOperation x y = safeSquareRoot =<< safeDivide x y main :: IO () main = do print $ complexOperation 100 2 -- Output: Just 10 print $ complexOperation 100 0 -- Output: Nothing 2. C++: The Challenge of Context-Aware Computations In contrast to Haskell, C++ does not have direct constructs derived from category theory. It needs to combine two tools to simulate Haskell's applicative for handling exceptions: std::function and std::optional. Consequently, C++ requires more verbosely explicit checks and manual handling of potential failures, leading to less concise and more error-prone code. #include <iostream> #include <functional> #include <optional> std::optional<int> safeDivide(int x, int y) { if (y == 0) return std::nullopt; return x / y; } std::optional<int> safeSquareRoot(int x) { if (x < 0) return std::nullopt; return static_cast<int>(sqrt(x)); } template <typename T, typename F> auto applyOptional(const std::optional<T>& opt, F func) -> std::optional<decltype(func(opt.value()))> { if (!opt.has_value()) return std::nullopt; return func(opt.value()); } int main() { std::function<std::optional<int>(int, int)> divideFunc = safeDivide; std::function<std::optional<int>(int)> squareRootFunc = safeSquareRoot; int x = 100, y = 2; auto result = applyOptional(divideFunc(x, y), squareRootFunc); if (result.has_value()) { std::cout << "Result: " << result.value() << std::endl; } else { std::cout << "Operation failed." << std::endl; } return 0; } Haskell's approach, grounded in theoretical concepts, offers a more efficient and error-resistant way of dealing with complex computations, while C++ requires a more hands-on and careful approach due to the lack of direct mathematical abstractions.
To view or add a comment, sign in
-
In this blog post I attempt to provide a guide on Unicode and Haskell strings and how to choose between the various different types. https://lnkd.in/gC96v9fQ
The ultimate guide to Haskell Strings
hasufell.github.io
To view or add a comment, sign in