Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
    Aaron Hall, MBA
    I want to put the source on github, and maybe update it...
    actually I've been looking for Reuben Thomas, but he just was the latest revisor...
    I'll look at the other names listed...
    Aaron Hall, MBA
    I created a repo - I hope nothing bad happens: https://github.com/aaronchall/haskell-98-tutorial-sources/tree/master

    Hello, everyone, I'm new to haskell:

    fibonacci_last_digit = helper (0, 1)
        helper (a, _) 0 = a `mod` 10
        --            ↥         
        helper (a, b) n = helper (b, a + b) (n - 1)
        --            ↥                       ↥

    Why helper is allowed to use 0/n/n-1 as parameter/argument here?

    Its type is Eq...
    The term to search for is 'pattern mathing'
    Thanks, I have searched and I know it is pattern matching(know a little sml). the function type is (b, b) -> t -> b and b is Integer, t is Eq. But i didn't see this systax in the articles from google.
    t is probably an integer too, in this case
    Eq is a type class, not a type
    Good to know type class, thanks
    I wonder is it just helper(a, b, c)'s syntax sugar in this case?
    The function application syntax in haskell is a little different than many other languages'
    Above, the first argument is (a, b) and the second is n
    (a,b) is a tuple
    Ok, a little different from sml. All parameters in sml are just a tuple
    helper (a, b, c) would mean something different: (a, b, c) would be a tuple of size 3
    Get it, thanks, Garmelon
    Giuseppe Cannella
    Do you know Scala? I'm playing with functors. Any ideas how to convert haskell code to Scala code? that below doesn't works
    replaceWithP = const 'p'
    lmls = [Just ["Ha", "Ha"], Nothing, Just []]
    (fmap . fmap . fmap . fmap) replaceWithP lmls
    -- [Just ["pp","pp"],Nothing,Just []]
    val lmls = List(Some(List("Ha", "Ha"), None))
    lmls.map(_.map(_.map(_.map(_ => 'p'))))
    Aaron Hall, MBA
    Why do people pronounce it "Haskal?"
    does anybody knows how to use guards? I can't find any information about it
    Снимок экрана 2018-11-04 в 21.00.22.png
    Guards, guards
    Aaron Hall, MBA
    @ericdwhite guards are kinda nice, right?
    does anybody know how to find indexes of element in list?
    Javier Sagredo
    Hey there, I am using the Binary type class for serializing and deserializing things and runGet's result is as expected but prefixed with a chunk of 7 \nul characters and another one marking the length of the resulting string.
    I mean, If i expected the ByteString (as chars are enums i'm gonna represent it as ints) [1,2,3] to result from runGet, what I get is [\nul, \nul, \nul, \nul, \nul, \nul, \nul, 3, 1, 2, 3]
    The returning type is Data.ByteString.Lazy.ByteString. Does it has something to do with those nul values? are all lazy bytestrings preceded by seven zero values?
    Hey guys! Can you help me with this? When trying to compile this file an error occurs saying "couldn't match Double with actual type Int".
    faculty :: Int -> Int
    faculty 0 = 1
    faculty n = n * faculty (n-1)
    cos :: Double -> Double
    cos x = sum [cos| k <- [0..],let cos = (-1) * (x^(2*k) `div` faculty (2*k)) , abs (cos) > 0.001]
    Miguel Alché
    Hey guys, can someone explain to me how does this work? What is flip flipping?
    applyFunctions :: a -> [a->b] -> [b]
    applyFunctions a = map (flip ($) a)
    Aly-Bocar Cissé
    flip reverse arguments of a function
    Adrian Legaspi
    flip :: (a -> b -> c) -> b -> a -> c
    Moisés Vázquez
    @miguelalche Basically
    applyFunctions a fs = [f a | f <- fs ]
    Adrian Legaspi
    @gittygit8 I’m months late but you should apply fromIntegral on those numbers because Haskell doesn’t implicitly convert Int to Double reason for it is strict typing and typesafety
    Francisco Albert Albusac
    hi people!
    Hi everyonem I am trying out this example:
    -- Tic-tac-toe example from chapter 11 of Programming in Haskell,
    -- Graham Hutton, Cambridge University Press, 2016.
    -- Basic declarations
    import Data.Char
    import Data.List
    import System.IO
    size :: Int
    size = 3
    type Grid = [[Player]]
    data Player = O | B | X
                  deriving (Eq, Ord, Show)
    grid :: Grid
    grid = [[B,O,O],[O,X,O],[X,X,X]]
    next :: Player -> Player
    next O = X
    next B = B
    next X = O
    -- Grid utilities
    empty :: Grid 
    empty = replicate size (replicate size B)
    full :: Grid -> Bool
    full = all (/= B) . concat
    turn :: Grid -> Player
    turn g = if os <= xs then O else X
                os = length (filter (== O) ps)
                xs = length (filter (== X) ps)
                ps = concat g
    wins :: Player -> Grid -> Bool
    wins p g = any line (rows ++ cols ++ dias)
                  line = all (== p)
                  rows = g
                  cols = transpose g
                  dias = [diag g, diag (map reverse g)]
    diag :: Grid -> [Player]
    diag g = [g !! n !! n | n <- [0..size-1]]
    won :: Grid -> Bool
    won g = wins O g || wins X g
    -- Displaying a grid
    putGrid :: Grid -> IO ()
    putGrid =
       putStrLn . unlines . concat . interleave bar . map showRow
       where bar = [replicate ((size*4)-1) '-']
    showRow :: [Player] -> [String]
    showRow = beside . interleave bar . map showPlayer
                 beside = foldr1 (zipWith (++))
                 bar    = replicate 3 "|"
    showPlayer :: Player -> [String]
    showPlayer O = ["   ", " O ", "   "]
    showPlayer B = ["   ", "   ", "   "]
    showPlayer X = ["   ", " X ", "   "]
    interleave :: a -> [a] -> [a]
    interleave x []     = []
    interleave x [y]    = [y]
    interleave x (y:ys) = y : x : interleave x ys
    row= [O,B,B]
    why I cannot partially run this part?
    *Main> showRow row
    ["   |   |   "," O |   |   ","   |   |   "]
    *Main> (interleave bar) . (map showPlayer row)
    <interactive>:68:21: error:
        • Couldn't match expected type ‘a -> [[[Char]]]’
                      with actual type ‘[[String]]’
        • Possible cause: ‘map’ is applied to too many arguments
          In the second argument of ‘(.)’, namely ‘(map showPlayer row)’
          In the expression: (interleave bar) . (map showPlayer row)
          In an equation for ‘it’:
              it = (interleave bar) . (map showPlayer row)
        • Relevant bindings include
            it :: a -> [[[Char]]] (bound at <interactive>:68:1)
    how to config haskell development IDE?I current use emacs to edit haskell as text file
    Michael Hoffmann
    Hey Everyone, i wrote a small "library" to quickly write arbitrary load-tests (database, http, ..). Would anyone like review the code? I'm quite new to haskell and would love to improve (https://gitlab.com/michoffmann/load)

    Hey people

    Can someone explain why I am getting this

       Expected type: IO Main.Result
       Actual type: t0 Maybe Main.Result

    What I am doing is the following

    fetchVods :: [Customer] -> IO [Vod]
    fetchVods customers = undefined
    handleCustomerVods :: Customer -> Main.Result
    handleCustomerVods = undefined
    checkForFail :: Main.Result -> Maybe Main.Result
    checkForFail r = case r of { OK -> Nothing;
                                 FAIL -> Just FAIL
    main = do
       args <- execParser opts
       result <- lift $ generateVodCsvForCustomers args
       display args
         opts = info (set_config <**> helper)
            ( fullDesc
              <> progDesc "Generate Vod CSV customers"
              <> header "CSV Generator"
         generateVodCsvForCustomers config = firstJust (checkForFail) $ (fmap handleCustomerVods $ customers config)

    Does this make sense? Why is t0 not being implicitly mapped as IO, since ints a context of IO ?
    Assuming that lift is not to be used, what is the alternative?

    Is haskell community slowly dying here? Or just dead?
    Alejandro Martinez
    or maybe in holidays xD Hi everyone from Barcelona
    what books are you reading to improve your Haskell? Is there any book to build microservices in haskell?
    What is reactive programming in Haskell ? I am referring to https://www.reactivemanifesto.org/. Is a functional language appropriate for that ?