相关疑难解决方法(0)

在Haskell中,你能创建一个类的对象吗?

在我正在尝试调试的Haskell程序中,定义了一个类:

class Dictionary d where
  lookupIn :: d -> Word -> String
Run Code Online (Sandbox Code Playgroud)

我想创建一个名为的变量runs并使其成为类型,Dictionary以便我可以在lookupIn函数中使用它.然而,没有任何工作.我试过了type runs = Dictionary,甚至data runs = Dictionary没有任何工作.

haskell types class

2
推荐指数
2
解决办法
1499
查看次数

如何在 Haskell 中使用数据结构?

我被分配制作一个包含学生数组(应该包含学生数据)的简单程序,我知道 Haskell 不是面向对象的编程语言,我正在寻找一种构建学生数据的方法,我想到了嵌套元组进入数组,然后进入学生数组,但问题是我有不同的数据类型(String,int ...等),所以元组不起作用,我还在Stack Overflow上找到了这个答案,它创建了一个新的数据类型根据我的理解,但我未能实现它,这是我尝试过的:

data Student =
  Student { name :: Char
   , surename :: Char 
   , moy1 :: Int
   , coef1 :: Int
   , moy2 :: Int
   , coef2 :: Int
   , moy3 :: Int
   , coef3 :: Int
   , mg :: Int 
   }

main :: IO ()
main = do 
 putStrLn "Enter students data:"
 students <- initializeStudents 10
 putStrLn "calculate student average ?"
 if(reponse == "yes") then putStrLn "Enter the student firstname"
                           first <- getLine …
Run Code Online (Sandbox Code Playgroud)

haskell

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

在Haskell中调用嵌套函数

我已经定义了一个名为函数initials内部的函数person,但我无法弄清楚如何在initials外面调用person:

main =
    --I attempted to print the output of the initials function here.
    (putStrLn ((person "firstName" "lastName") . initials)) --Not in scope: `initials'
    --If this function call worked correctly, the output would be "f.l.".

person firstName lastName =
    firstName ++ ["."] ++ lastName
    where
        fullName = firstName ++ " " ++ lastName
        firstInitial = firstName !! 0
        lastInitial = lastName !! 0
        initials = [firstInitial] ++ "." ++ [lastInitial] ++ "." …
Run Code Online (Sandbox Code Playgroud)

haskell nested-function

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

标签 统计

haskell ×3

class ×1

nested-function ×1

types ×1