小编Sag*_*tha的帖子

了解如何应用haskell applicative仿函数

我只是有一个关于应用函子的快速问题,以帮助我掌握它们.这只是我在ghci中应用的东西.

[(+3),((-) 3),(*3)] <*> [4]
[7,-1,12]
Run Code Online (Sandbox Code Playgroud)

这对我来说很有意义.基本申请.但在尝试时:

[(Just (+3)),(Just ((-) 3)),(Just (*3))] <*> [Just 4]
Run Code Online (Sandbox Code Playgroud)

我收到了很多错误.我有点理解为什么; 有两个数据构造函数([]Maybe),并且该<*>函数仅"剥离"其中一个.我想要帮助我理解的是,haskell正在尝试逐步进行直到失败,以及如何绕过它并将其成功计算到:

[(Just 7),(Just -1),(Just 12)]
Run Code Online (Sandbox Code Playgroud)

monads haskell applicative maybe

1
推荐指数
1
解决办法
77
查看次数

初学者haskell代码在main中使用do构造获取类型错误

我只是学习了一些轻便的haskell代码,但是我一直关注的教程没有提到我在尝试使用do和I/O类型运行任何代码时仍然会遇到此错误.GHCI似乎认为它有些类型错误.这是我的代码:

main = do
  putStrLn "This program can find all odd numbers between 1 and a desired number. Please enter a number."
  user <- getLine
  if (read user) < 1
      then
        do putStrLn "Improper input specified. 10 will be chosen as     default."
            putStrLn show oddsort 10 [] ++ "Is the list of odd numbers from 1 to 10."
    else
      do putStrLn show (oddsort (read user) [])

oddsort x xs
  |x == 1 = 1:xs
  |x `mod` 2 == 0 = …
Run Code Online (Sandbox Code Playgroud)

haskell

-1
推荐指数
1
解决办法
85
查看次数

Haskell-在List Monad中期望[Char]时获取Char类型

我正在通过尝试创建一个查找.mp3和.flac元数据并将其整齐地写入文件的程序来练习Haskell。我已经走了这么远,但是我对应该做的事情感到很沮丧。这是这里的主要代码块:

builddir xs = do
    writeto  <- lastest getArgs
    let folderl b = searchable <$> (getPermissions b)
    let filel   c = ((lastlookup mlookup c) &&) <$> ((not <$> folderl c))
    a <- listDirectory xs
    listdirs <- filterM (folderl) (map ((xs ++ "/") ++) a)
    filedirs <- filterM (filel)   (map ((xs ++ "/") ++) a)
    let tagfiles = mapM (tagsort) filedirs
    putStrLn $ concat listdirs
    putStrLn $ concat tagfiles


tagsort xs = do
    nsartist <- getTags xs artistGetter
    nsalbum  <- getTags …
Run Code Online (Sandbox Code Playgroud)

io monads haskell

-1
推荐指数
1
解决办法
49
查看次数

标签 统计

haskell ×3

monads ×2

applicative ×1

io ×1

maybe ×1