r/haskellquestions • • Jan 25 '22

german haskell programmer

0 Upvotes

is here a german haskell programmer who can help me with 2 simple haskell programs?


r/haskellquestions • • Jun 03 '23

Maybe Int

0 Upvotes

Ok friends, chatGPT has failed me and I am really stumped on this one, I need your help.
|
In the code below, how does "case eval x of" yield "Nothing" when I have not yet defined eval x to yield "Nothing"? In other words, how does it know HOW eval x yields "Nothing"? No definition of it yielding "Nothing" has been provided.
|
I can see how it determines the "Just n" constructor as the eval function is recursive and "Just n" is in the base case. But I am stumped on the "Nothing" as I have clearly not even derived it when I defined the "Expr" type.
|
data Expr = Val Int | Div Expr Expr
|
safeDiv :: Integral a => a -> a -> Maybe a
safeDiv _ 0 = Nothing
safeDiv x y = Just (x `div` y)
|
eval :: Expr -> Maybe Int
eval (Val n) = Just n
eval (Div x y) = case eval x of
____Nothing -> Nothing
____Just n -> case eval y of
________Nothing -> Nothing
________Just m -> safeDiv n m


r/haskellquestions • • Jun 13 '23

Haskell installation

0 Upvotes

I wrote what I do to install Haskell.

https://medium.com/p/c4874c7706fb


r/haskellquestions • • Feb 15 '17

What's the best way to divide 500,000-digit Integers by 400,000 digit Integers, when it's known that the result will be an Integer?

0 Upvotes

r/haskellquestions • • Jun 23 '21

How should I declare this function?

0 Upvotes

How should I declare a function that takes four doubles and an integer, returning a list of undetermined number of elements with the format [(Double, Double), (Double, Double),...]


r/haskellquestions • • Jul 10 '22

Fill an array with all 1s between 1 and 1

0 Upvotes

Try to fill an array with following pattern

Given an array s = [0, 1, 0, 1, 0] Fill all 1s between 1 and 1

  0 1 0 1 0
=>0 1 1 1 0

  0 1 0 0 1 0
    |     |
=>0 1 1 1 1 0
  
  0 1 0 0 1 0 1 0 1 0
    |     |   |   |
=>0 1 1 1 1 0 1 1 1 0
  
  0 1 0 0 1 0 1 0
    |     |
=>0 1 1 1 1 0 1 0
              ↑
               + -> Do nothing for only one 1

I try to use scanl1

   scanl1 (\a b -> a /= b ? 1 $ 0) [0, 1, 0, 1, 0]
   => [0, 1, 1, 0, 0]

r/haskellquestions • • Feb 25 '20

Why is do notation so popular?

1 Upvotes

It's pretty easy to use >>= and do isn't generic. There are many similar map functions (EG: fmap, traverse and <*>) but there's no similar syntax sugar. Haskell is very abstract and keywords like this should be generic. I guess if then else shouldn't be keywords either, since a simple function can achieve that. Otherwise you'd include ifM thenM elseM as keywords.


r/haskellquestions • • May 01 '24

Designing chips for Haskell using RISC-V?

1 Upvotes

I am no expert on Haskell but ChatGPT brought up some interesting points and I wanted to get some opinions here:

Yes, chip design could indeed be different if pure functional languages like Haskell were more mainstream, especially when considering the development and optimization of hardware like RISC-V processors. Here's how this could influence design philosophies and practical implementations:

1. Hardware Tailored for Functional Paradigms

Functional languages, particularly pure ones like Haskell, emphasize immutability and stateless computation. If such languages were mainstream, chip designs might prioritize features that optimize for these characteristics:

  • Immutability Optimization: Hardware could include specialized cache architectures or memory management units designed to efficiently handle the frequent allocation and deallocation of immutable data structures.

  • Parallel Processing Enhancements: Given Haskell's strong support for concurrency and parallel processing, chips might incorporate more advanced support for parallel execution paths, enhancing multicore processing and thread management at the hardware level.

2. Energy Efficiency and Determinism

Functional languages can lead to more predictable and deterministic software behavior, which is a boon for designing energy-efficient and reliable systems:

  • Predictable Performance: Optimizations in the chip for functional constructs might include enhanced branch prediction algorithms and instruction pipelines tailored to the typical execution patterns of functional code, reducing runtime surprises and enhancing power efficiency.

  • Reduced Side Effects: With fewer side effects by design, chips might require less complex mechanisms for handling state changes, potentially simplifying chip architectures.

3. Compilers and ISA Extensions

The compiler technology needed to efficiently translate high-level Haskell code to machine instructions could drive innovations in Instruction Set Architecture (ISA) extensions specific to functional programming constructs:

  • Custom ISA Extensions: RISC-V, being an open and extensible ISA, could see the development of custom extensions that support high-level functional programming abstractions directly in the hardware, such as optimized tail-call recursion, lazy evaluation, or even function caching mechanisms.

  • Advanced Compiler Techniques: Compilers might evolve to take advantage of these hardware features, optimizing the way functional code is executed at the chip level, perhaps by altering the conventional approaches to compiling and executing code.

4. Impact on Chip Testing and Verification

The deterministic nature of pure functional languages could simplify the testing and verification of chip designs:

  • Formal Verification: The mathematical rigor inherent in functional programming aligns well with formal methods for hardware verification. This synergy could lead to more robust methodologies for verifying chip designs against their specifications, reducing bugs and increasing reliability.

  • Simulation and Modeling: Tools for simulating and modeling chip behavior could become more sophisticated, leveraging functional paradigms to ensure accuracy and consistency in simulations.

5. Software-Hardware Co-Design

In a world where functional languages are mainstream, the co-design of software and hardware could become more prevalent, with both domains influencing each other to a greater extent:

  • Co-Optimization: Software written in Haskell might influence hardware design decisions from the outset, leading to a more integrated approach where software requirements directly shape hardware features and vice versa.

  • Cross-Disciplinary Tools: Development tools might merge concepts from both software and hardware design, supporting a seamless environment for developing, testing, and deploying applications in a Haskell-centric ecosystem.

In conclusion, if pure functional languages like Haskell were mainstream, we would likely see a shift in chip design towards architectures that inherently support the characteristics of functional programming. This could result in innovations not just at the level of individual chips but also in the broader ecosystem of tools and methodologies used for designing, testing, and verifying hardware.

Are there any active projects out there doing anything like this? This seems especially relevant with how parallel computing is key to AI development and how power consumpition seems to be a lmiting factor on the horizon.


r/haskellquestions • • Feb 07 '23

How to install Haskell in windows?

2 Upvotes

can you give videos to install in windows?


r/haskellquestions • • Jan 09 '17

How come Haskell Strings (at least when `putStrLn`d) don't support at least full ASCII?

0 Upvotes

I mean ASCII is older than Haskell, and just 256 simple possible values. I've served funky chars such as × and ± to command-line jocks even in QBasic and Turbo Pascal some 20 years ago.. (OK not really as fancy, just the various blocks-and-lines for pretend-"windows")

Now Haskell (or GHC) chooses to quit on me with <stdout>: commitBuffer: invalid argument (invalid character) or even without any message, depending on the Char?!


r/haskellquestions • • Jan 14 '20

overloading operator < and > as one operator like array index in Cpp or Java

0 Upvotes

Is possible to overloading < and > as one operator in Haskell?

e.g.

list = [1, 2, 3]
list<1> = 2
list<0> = 1

r/haskellquestions • • Sep 19 '21

Tooling and dependency management

1 Upvotes

Ok, let's start with what's really in my mind: Yo, Haskell, WTF are you doing with the tools like cabal and the likes?


Now, I've this piece of code I wrote five month ago. At the time, I started anew and coded this library with a pair of executables using it. All in the same git repository with CI/CD.

It was perfectly functional (haha).

I felt like the code needs an update, came back to it yesterday after reinstalling ghcup. I can't cabal build my code.

The .cabal file seems outdated, the cabal tool now has new-* commands and everything seems different than five month ago.


I know this is not a really constructive post but seriously, this sucks compared to the rust ecosystem for example.


r/haskellquestions • • Aug 05 '20

help with, emacs/elisp/haskell: after running `ein:run` to activate, emacs-ipython-notebook, how to `only trigger` this elisp code for haskell dante whenever whenever an .ipynb file is opened:

0 Upvotes

;;------------------------------------------------------------------

;; haskell-mode configuration:

(use-package dante

:ensure t

:after haskell-mode

:commands 'dante-mode

:init

(add-hook 'haskell-mode-hook 'flycheck-mode)

;; OR:

;; (add-hook 'haskell-mode-hook 'flymake-mode)

(add-hook 'haskell-mode-hook 'dante-mode)

)

;;------------------------------------------------------------------


r/haskellquestions • • Apr 03 '23

Ho to add OPTIONS to servant application type

1 Upvotes

I guess that Header combinator could be used here, but I'm not sure.
Don't advice some wai-cors, servant-options
I need to do it "with my hands"
Thank you :)


r/haskellquestions • • May 08 '23

KnownSymbol problem

0 Upvotes

Hello everyone,
I have the next code

class KnownSymbol sym => Name sym where
call :: Proxy sym
call = Proxy

data family ( key :: forall sym . Name sym => sym ) := value

And the error I've caught:
• Expected a type, but ‘sym’ has kind ‘Symbol’
• In the kind ‘forall sym. Name sym => sym’
In the data family declaration for ‘:=’

I need to implement a constraint Name to the key of data family

I need it to use something like that
instance Name "John"
newtype instance ("John" := Int) ...

Could someone help me?


r/haskellquestions • • Oct 26 '21

How to use a function in another function?

0 Upvotes

foo :: String

foo = "My string"

makeConc :: String -> String -> String

makeConc = foo ++ foo

main = makeConc

How would I use the foo function in the makeConc function?

Similarly, how to call makeConc from main?


r/haskellquestions • • Oct 10 '18

Multiple variables defined inside function

0 Upvotes

I get error on this code if i want ot declare second variable

foo x =

y + yy

where y = x + 1

yy = (-x)

My example is much more complicated, this is simplifed version. I can't find example of declaring multiple variable inside function. Is this incorect way of thinking and I should add two functions as parameters instead?


r/haskellquestions • • Dec 20 '19

Unable to add classy-prelude dependency

0 Upvotes

Hi all

I am trying to add classy-prelude dependency to my stack project as follows:

name:                FooService
version:             0.1.0.0
github:              "githubuser/FooService"
license:             BSD3
author:              "Author name here"
maintainer:          "[email protected]"
copyright:           "2019 Author name here"

extra-source-files:
- README.md
- ChangeLog.md

# Metadata used when publishing your package
# synopsis:            Short description of your package
# category:            Web

# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description:         Please see the README on GitHub at <https://github.com/githubuser/FooService#readme>

dependencies:
- base >= 4.7 && < 5
- classy-prelude

default-extesion:
- NoImplicitPrelude
- OverloadedStrings

library:
  source-dirs: src

executables:
  FooService-exe:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - FooService

tests:
  FooService-test:
    main:                Spec.hs
    source-dirs:         test
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - FooService

when call the interactive environment I've got the error message:

Using main module: 1. Package `FooService' component FooService:exe:FooService-exe with main-is file: /home/developer/haskell/FooService/app/Main.hs Cabal file info not found for classy-prelude-1.5.0@sha256:ed1a607f688745bc263be0b2ed2492729a62fd4c9821b68c2bfacbd7a9d9293d,1928, updating Selected mirror https://s3.amazonaws.com/hackage.fpcomplete.com/ Downloading timestamp No package index update available, but didn't update cache last time, running now Calculating hashes to check for hackage-security rebases or filesystem changes Updating preexisting cache, should be quick Populating cache from file size 640326144, hash bb56d41c70c9e6cdd625a6c3c7de5f56823e92cc6fe880f8056259ab31d3e0d5 Populating package index cache ... Failed populating package index cache

Error: BadChecksum 0

Warning: Build failed, but trying to launch GHCi anyway The following GHC options are incompatible with GHCi and have not been passed to it:
-threaded Configuring GHCi with the following packages: FooService GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help <command line>: cannot satisfy -package classy-prelude-1.5.0  

What is missing?

Thanks


r/haskellquestions • • Sep 27 '17

Why does not get evaluate?

0 Upvotes

Hi all

I have following code snippet:

*Main Lib> let myList = [1, 2, id 1] :: [Integer]
*Main Lib> let myList' = myList ++ undefined
*Main Lib> :sprint myList'
myList' = _

Why does the myList does not get evaluated?

And this too:

*Main Lib> x = 45
*Main Lib> :sprint x
x = _

Let's consider the first example. When I write *Main Lib> myList ++ undefined then it is an application and it gets evaluated.

When I write let myList' = myList ++ undefined is a lambda abstraction, that why it does not get evaluated, right?

Thanks


r/haskellquestions • • Nov 08 '22

Why am I getting an error in the third test? What, in my types, is incorrect?

0 Upvotes

type EitherMaybe = Either String (Maybe Integer)
spec :: Spec
spec = do
    describe "firstFunctorLaw" $ do
//test 1 below works fine
        it "First functor law" $
         firstFunctorLaw [1,2,3]  `shouldBe` True

//test 2 below works fine
        it "First functor law" $
         firstFunctorLaw ('c', 35) `shouldBe` True

//I am getting an error here, Either and Maybe are both red underlined
        it "First functor law" $
         firstFunctorLaw ( Either ('c','d') Maybe (Nothing):: EitherMaybe) `shouldBe` True


r/haskellquestions • • Apr 19 '24

This is a code I got from chatgpt for a collatz conjecture problem. I don't understand how the count is being tracked and what fmap is adding to. Looking for an explanation

0 Upvotes

module CollatzConjecture (collatz) where
collatz :: Integer -> Maybe Integer
collatz n
| n <= 0 = Nothing
| n == 1 = Just 0
| even n = fmap (+1) (collatz (n `div` 2))
| odd n = fmap (+1) (collatz (3 * n + 1))


r/haskellquestions • • Aug 17 '26

Idiomatic Haskell Agent Skill

0 Upvotes

I put together a rough Agent Skill for idiomatic Haskell, based on what seemed to be the consensus in the discussion thread
https://www.reddit.com/r/haskellquestions/comments/xsee5x/what_is_idiomatic_haskell_style/.

Curious what you think!

https://gist.github.com/lbobylev/0577fff8755bacefcf954a64f9226955


r/haskellquestions • • Apr 02 '20

how to ignore function my my source code?

2 Upvotes

Hi,

does anyone know whether I can ignore a function in my source code in Haskell?

addOne::Int -> Int
addOne = (+1)

How can make the compiler to ignore addOne in my source code without using comment syntax.


r/haskellquestions • • Jun 19 '21

Potential New Rule: OP participation in comments

4 Upvotes

I've seen a string of Posts where someone asks a vague question, then several helpful Haskellers will comment asking for details and clarification. Several days will pass, and the OP will not address any of the commenter's requests. Such posts languish without solutions and crowd out other useful posts that actually address meaningful questions.

Proposed Rule 2: OP Participation

Please participate in your posts. If commenters ask for details or clarification, please help them help you. Posts that remain unanswered and lack OP participation for 72 hours will be marked as spam or removed.

56 votes, Jun 22 '21
46 In favor. Such a rule would enhance the community.
10 Opposed: Such a rule would harm the community.
0 Other (add a comment)