Note that there are some explanatory texts on larger screens.

plurals
  1. POHaskell - declare/use data
    text
    copied!<p>It's my first time to use data types in Haskell. Got a problem and I don't know how to improve the code.</p> <p>Here is the problem:</p> <p>Declear a data type called "Consonant" which include some letters(string), and an textstring which got the information about if all the letters in that word are consonant or not (string), then write a function "Cheak" which got indata (some letters to cheak) and outdata (the data type "Consonant").</p> <p>Here is my code:</p> <pre><code>module Consonant where import Char type Name = String type ConOrNot = String data Consonant = Cons Name ConOrNot deriving (Show,Eq) isVowel = "AEIOU" cheak :: String -&gt; Consonant cheak [] = "" cheak (char:chars) = if elem (toUpper char) isVowel == false then cheak chars else cheak = Cons (char:chars) "Not Consonant" -- here I want to use "break", but I don't know how to use it in Haskell... cheak = Cons (char:chars) "Is Consonant" </code></pre> <p>It doesn't work... How to change the code? Pls help! Thank you!</p> <p>Update:</p> <pre><code> module Consonant where import Char type Word = String type ConOrNot = String data Consonant = Cons Word ConOrNot deriving (Show,Eq) isConsonant = "BCDFGHJKLMNPQRSTVWXYZ" cheak :: String -&gt; Consonant cheak [] = Cons "" "" cheak (char:chars) |elem (toUpper char) isCosonant = cheak chars --if all the letters are cosonant, I want it return (Cons (char:chars) "is Consonant").. still working on it |otherwise = Cons (char:chars) "Not Consonant" </code></pre> <p>It works now if the string got both vowels and consonant or only vowels, how to improve the code so it also works with only consonants?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload